klist.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* vcc/klist.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc 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. * vcc 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 vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <sys/types.h>
  19. #include <stddef.h>
  20. #include <klist.h>
  21. void klist_init(struct klist_node *head) {
  22. head->next = head;
  23. head->prev = head;
  24. head->usrname = NULL;
  25. return;
  26. }
  27. void klist_add(struct klist_node *head, struct klist_node *new) {
  28. /* head->prev: the last. */
  29. new->prev = head->prev;
  30. new->next = head;
  31. /* head->prev->next: (was) the head */
  32. head->prev->next = new;
  33. head->prev = new;
  34. return;
  35. }
  36. void klist_del(struct klist_node *head, struct klist_node *will_del) {
  37. (void) head;
  38. will_del->prev->next = will_del->next;
  39. will_del->next->prev = will_del->prev;
  40. return;
  41. }