klist.c 1.5 KB

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