list.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* list.c - grub list function */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2009 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/list.h>
  20. #include <grub/misc.h>
  21. #include <grub/mm.h>
  22. void *
  23. grub_named_list_find (grub_named_list_t head, const char *name)
  24. {
  25. grub_named_list_t item;
  26. FOR_LIST_ELEMENTS (item, head)
  27. if (grub_strcmp (item->name, name) == 0)
  28. return item;
  29. return NULL;
  30. }
  31. void
  32. grub_list_push (grub_list_t *head, grub_list_t item)
  33. {
  34. item->prev = head;
  35. if (*head)
  36. (*head)->prev = &item->next;
  37. item->next = *head;
  38. *head = item;
  39. }
  40. void
  41. grub_list_remove (grub_list_t item)
  42. {
  43. if (item->prev)
  44. *item->prev = item->next;
  45. if (item->next)
  46. item->next->prev = item->prev;
  47. item->next = 0;
  48. item->prev = 0;
  49. }