search_list.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* search-list.c
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. This file is part of GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #include "gprof.h"
  17. #include "libiberty.h"
  18. #include "search_list.h"
  19. void
  20. search_list_append (Search_List *list, const char *paths)
  21. {
  22. Search_List_Elem *new_el;
  23. const char *beg, *colon;
  24. unsigned int len;
  25. colon = paths - 1;
  26. do
  27. {
  28. beg = colon + 1;
  29. colon = strchr (beg, PATH_SEP_CHAR);
  30. if (colon)
  31. len = colon - beg;
  32. else
  33. len = strlen (beg);
  34. new_el = (Search_List_Elem *) xmalloc (sizeof (*new_el) + len);
  35. memcpy (new_el->path, beg, len);
  36. new_el->path[len] = '\0';
  37. /* Append new path at end of list. */
  38. new_el->next = 0;
  39. if (list->tail)
  40. list->tail->next = new_el;
  41. else
  42. list->head = new_el;
  43. list->tail = new_el;
  44. }
  45. while (colon);
  46. }