dlist.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * dlist.h - macros for handling doubly linked lists
  3. *
  4. * Copyright © 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
  5. *
  6. * This program 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 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ADNS_DLIST_H_INCLUDED
  20. #define ADNS_DLIST_H_INCLUDED
  21. #define LIST_INIT(list) ((list).head = (list).tail = NULL)
  22. #define LINK_INIT(link) ((link).next = (link).prev = NULL)
  23. #define LIST_UNLINK_PART(list, node, part) \
  24. do { \
  25. if ((node)->part prev) \
  26. (node)->part prev->part next = (node)->part next; \
  27. else \
  28. (list).head = (node)->part next; \
  29. if ((node)->part next) \
  30. (node)->part next->part prev = (node)->part prev; \
  31. else \
  32. (list).tail = (node)->part prev; \
  33. } while (0)
  34. #define LIST_LINK_TAIL_PART(list, node, part) \
  35. do { \
  36. (node)->part next = NULL; \
  37. (node)->part prev = (list).tail; \
  38. if ((list).tail) \
  39. (list).tail->part next = (node); \
  40. else (list).head = (node); \
  41. (list).tail = (node); \
  42. } while (0)
  43. #define LIST_UNLINK(list, node) LIST_UNLINK_PART(list, node,)
  44. #define LIST_LINK_TAIL(list, node) LIST_LINK_TAIL_PART(list, node,)
  45. #endif