xref: /netbsd-src/external/gpl3/binutils.old/dist/gprof/search_list.c (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* search-list.c
275fd0b74Schristos 
3*e992f068Schristos    Copyright (C) 2000-2022 Free Software Foundation, Inc.
475fd0b74Schristos 
575fd0b74Schristos    This file is part of GNU Binutils.
675fd0b74Schristos 
775fd0b74Schristos    This program is free software; you can redistribute it and/or modify
875fd0b74Schristos    it under the terms of the GNU General Public License as published by
975fd0b74Schristos    the Free Software Foundation; either version 3 of the License, or
1075fd0b74Schristos    (at your option) any later version.
1175fd0b74Schristos 
1275fd0b74Schristos    This program is distributed in the hope that it will be useful,
1375fd0b74Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1475fd0b74Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1575fd0b74Schristos    GNU General Public License for more details.
1675fd0b74Schristos 
1775fd0b74Schristos    You should have received a copy of the GNU General Public License
1875fd0b74Schristos    along with this program; if not, write to the Free Software
1975fd0b74Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
2075fd0b74Schristos    02110-1301, USA.  */
2175fd0b74Schristos 
2275fd0b74Schristos #include "gprof.h"
2375fd0b74Schristos #include "libiberty.h"
2475fd0b74Schristos #include "search_list.h"
2575fd0b74Schristos 
2675fd0b74Schristos 
2775fd0b74Schristos void
search_list_append(Search_List * list,const char * paths)2875fd0b74Schristos search_list_append (Search_List *list, const char *paths)
2975fd0b74Schristos {
3075fd0b74Schristos   Search_List_Elem *new_el;
3175fd0b74Schristos   const char *beg, *colon;
3275fd0b74Schristos   unsigned int len;
3375fd0b74Schristos 
3475fd0b74Schristos   colon = paths - 1;
3575fd0b74Schristos   do
3675fd0b74Schristos     {
3775fd0b74Schristos       beg = colon + 1;
3875fd0b74Schristos       colon = strchr (beg, PATH_SEP_CHAR);
3975fd0b74Schristos 
4075fd0b74Schristos       if (colon)
4175fd0b74Schristos 	len = colon - beg;
4275fd0b74Schristos       else
4375fd0b74Schristos 	len = strlen (beg);
4475fd0b74Schristos 
4575fd0b74Schristos       new_el = (Search_List_Elem *) xmalloc (sizeof (*new_el) + len);
4675fd0b74Schristos       memcpy (new_el->path, beg, len);
4775fd0b74Schristos       new_el->path[len] = '\0';
4875fd0b74Schristos 
4975fd0b74Schristos       /* Append new path at end of list.  */
5075fd0b74Schristos       new_el->next = 0;
5175fd0b74Schristos 
5275fd0b74Schristos       if (list->tail)
5375fd0b74Schristos 	list->tail->next = new_el;
5475fd0b74Schristos       else
5575fd0b74Schristos 	list->head = new_el;
5675fd0b74Schristos 
5775fd0b74Schristos       list->tail = new_el;
5875fd0b74Schristos     }
5975fd0b74Schristos   while (colon);
6075fd0b74Schristos }
61