klist.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* spearl/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 <spearl/klist.h>
  19. void spl_klist_init(struct spl_klist_node *head) {
  20. head->next = head;
  21. head->prev = head;
  22. return;
  23. }
  24. void spl_klist_add(struct spl_klist_node *head, struct spl_klist_node *new) {
  25. /* head->prev: the last. */
  26. new->prev = head->prev;
  27. new->next = head;
  28. /* head->prev->next: (was) the head */
  29. head->prev->next = new;
  30. head->prev = new;
  31. return;
  32. }
  33. void spl_klist_del(struct spl_klist_node *head, struct spl_klist_node *will_del) {
  34. (void) head;
  35. will_del->prev->next = will_del->next;
  36. will_del->next->prev = will_del->prev;
  37. return;
  38. }