/contrib/bind9/lib/lwres/include/lwres/list.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 121 lines · 88 code · 15 blank · 18 comment · 31 complexity · da93c8ab8b6d3bd21f26f4462eaf6c27 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1997-2001 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id: list.h,v 1.14 2007/06/19 23:47:23 tbox Exp $ */
  18. #ifndef LWRES_LIST_H
  19. #define LWRES_LIST_H 1
  20. /*! \file lwres/list.h */
  21. #define LWRES_LIST(type) struct { type *head, *tail; }
  22. #define LWRES_LIST_INIT(list) \
  23. do { (list).head = NULL; (list).tail = NULL; } while (0)
  24. #define LWRES_LINK(type) struct { type *prev, *next; }
  25. #define LWRES_LINK_INIT(elt, link) \
  26. do { \
  27. (elt)->link.prev = (void *)(-1); \
  28. (elt)->link.next = (void *)(-1); \
  29. } while (0)
  30. #define LWRES_LINK_LINKED(elt, link) \
  31. ((void *)((elt)->link.prev) != (void *)(-1))
  32. #define LWRES_LIST_HEAD(list) ((list).head)
  33. #define LWRES_LIST_TAIL(list) ((list).tail)
  34. #define LWRES_LIST_EMPTY(list) LWRES_TF((list).head == NULL)
  35. #define LWRES_LIST_PREPEND(list, elt, link) \
  36. do { \
  37. if ((list).head != NULL) \
  38. (list).head->link.prev = (elt); \
  39. else \
  40. (list).tail = (elt); \
  41. (elt)->link.prev = NULL; \
  42. (elt)->link.next = (list).head; \
  43. (list).head = (elt); \
  44. } while (0)
  45. #define LWRES_LIST_APPEND(list, elt, link) \
  46. do { \
  47. if ((list).tail != NULL) \
  48. (list).tail->link.next = (elt); \
  49. else \
  50. (list).head = (elt); \
  51. (elt)->link.prev = (list).tail; \
  52. (elt)->link.next = NULL; \
  53. (list).tail = (elt); \
  54. } while (0)
  55. #define LWRES_LIST_UNLINK(list, elt, link) \
  56. do { \
  57. if ((elt)->link.next != NULL) \
  58. (elt)->link.next->link.prev = (elt)->link.prev; \
  59. else \
  60. (list).tail = (elt)->link.prev; \
  61. if ((elt)->link.prev != NULL) \
  62. (elt)->link.prev->link.next = (elt)->link.next; \
  63. else \
  64. (list).head = (elt)->link.next; \
  65. (elt)->link.prev = (void *)(-1); \
  66. (elt)->link.next = (void *)(-1); \
  67. } while (0)
  68. #define LWRES_LIST_PREV(elt, link) ((elt)->link.prev)
  69. #define LWRES_LIST_NEXT(elt, link) ((elt)->link.next)
  70. #define LWRES_LIST_INSERTBEFORE(list, before, elt, link) \
  71. do { \
  72. if ((before)->link.prev == NULL) \
  73. LWRES_LIST_PREPEND(list, elt, link); \
  74. else { \
  75. (elt)->link.prev = (before)->link.prev; \
  76. (before)->link.prev = (elt); \
  77. (elt)->link.prev->link.next = (elt); \
  78. (elt)->link.next = (before); \
  79. } \
  80. } while (0)
  81. #define LWRES_LIST_INSERTAFTER(list, after, elt, link) \
  82. do { \
  83. if ((after)->link.next == NULL) \
  84. LWRES_LIST_APPEND(list, elt, link); \
  85. else { \
  86. (elt)->link.next = (after)->link.next; \
  87. (after)->link.next = (elt); \
  88. (elt)->link.next->link.prev = (elt); \
  89. (elt)->link.prev = (after); \
  90. } \
  91. } while (0)
  92. #define LWRES_LIST_APPENDLIST(list1, list2, link) \
  93. do { \
  94. if (LWRES_LIST_EMPTY(list1)) \
  95. (list1) = (list2); \
  96. else if (!LWRES_LIST_EMPTY(list2)) { \
  97. (list1).tail->link.next = (list2).head; \
  98. (list2).head->link.prev = (list1).tail; \
  99. (list1).tail = (list2).tail; \
  100. } \
  101. (list2).head = NULL; \
  102. (list2).tail = NULL; \
  103. } while (0)
  104. #define LWRES_LIST_ENQUEUE(list, elt, link) LWRES_LIST_APPEND(list, elt, link)
  105. #define LWRES_LIST_DEQUEUE(list, elt, link) LWRES_LIST_UNLINK(list, elt, link)
  106. #endif /* LWRES_LIST_H */