1b55d4692Sfgsch /* search-list.c
2b55d4692Sfgsch
3*c074d1c9Sdrahn Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
4b55d4692Sfgsch
5b55d4692Sfgsch This file is part of GNU Binutils.
6b55d4692Sfgsch
7b55d4692Sfgsch This program is free software; you can redistribute it and/or modify
8b55d4692Sfgsch it under the terms of the GNU General Public License as published by
9b55d4692Sfgsch the Free Software Foundation; either version 2 of the License, or
10b55d4692Sfgsch (at your option) any later version.
11b55d4692Sfgsch
12b55d4692Sfgsch This program is distributed in the hope that it will be useful,
13b55d4692Sfgsch but WITHOUT ANY WARRANTY; without even the implied warranty of
14b55d4692Sfgsch MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15b55d4692Sfgsch GNU General Public License for more details.
16b55d4692Sfgsch
17b55d4692Sfgsch You should have received a copy of the GNU General Public License
18b55d4692Sfgsch along with this program; if not, write to the Free Software
19b55d4692Sfgsch Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20b55d4692Sfgsch 02111-1307, USA. */
21b55d4692Sfgsch
222159047fSniklas #include "libiberty.h"
232159047fSniklas #include "gprof.h"
242159047fSniklas #include "search_list.h"
252159047fSniklas
262159047fSniklas
272159047fSniklas void
search_list_append(list,paths)28*c074d1c9Sdrahn search_list_append (list, paths)
29*c074d1c9Sdrahn Search_List *list;
30*c074d1c9Sdrahn const char *paths;
312159047fSniklas {
322159047fSniklas Search_List_Elem *new_el;
332159047fSniklas const char *beg, *colon;
34*c074d1c9Sdrahn unsigned int len;
352159047fSniklas
362159047fSniklas colon = paths - 1;
372159047fSniklas do
382159047fSniklas {
392159047fSniklas beg = colon + 1;
40f7cc78ecSespie colon = strchr (beg, PATH_SEP_CHAR);
41b55d4692Sfgsch
422159047fSniklas if (colon)
432159047fSniklas len = colon - beg;
442159047fSniklas else
452159047fSniklas len = strlen (beg);
46b55d4692Sfgsch
472159047fSniklas new_el = (Search_List_Elem *) xmalloc (sizeof (*new_el) + len);
482159047fSniklas memcpy (new_el->path, beg, len);
492159047fSniklas new_el->path[len] = '\0';
502159047fSniklas
51b55d4692Sfgsch /* Append new path at end of list. */
522159047fSniklas new_el->next = 0;
53b55d4692Sfgsch
542159047fSniklas if (list->tail)
552159047fSniklas list->tail->next = new_el;
562159047fSniklas else
572159047fSniklas list->head = new_el;
58b55d4692Sfgsch
592159047fSniklas list->tail = new_el;
602159047fSniklas }
612159047fSniklas while (colon);
622159047fSniklas }
63