klist.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* readconf/klist.c
  2. *
  3. * This file is part of readconf.
  4. *
  5. * readconf is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * readconf is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with readconf. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <readconf/klist.h>
  19. struct rc_klist_node *rc_klist_find_value(struct rc_klist_node *head, __uint32_t value) {
  20. struct rc_klist_node *t;
  21. for (t = head; t; t = t->next)
  22. if (t->value == value)
  23. return t;
  24. return NULL;
  25. }
  26. void rc_klist_init(struct rc_klist_node *head) {
  27. head->next = head;
  28. head->prev = head;
  29. head->value = 0;
  30. head->payload = NULL;
  31. return;
  32. }
  33. void rc_klist_add(struct rc_klist_node *head, struct rc_klist_node *new) {
  34. /* head->prev: the last. */
  35. new->prev = head->prev;
  36. new->next = head;
  37. /* head->prev->next: (was) the head */
  38. head->prev->next = new;
  39. head->prev = new;
  40. return;
  41. }
  42. void rc_klist_del(struct rc_klist_node *head, struct rc_klist_node *will_del) {
  43. will_del->prev->next = will_del->next;
  44. will_del->next->prev = will_del->prev;
  45. return;
  46. }