2 * Copyright (C) 1997, 1999 Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21 #define ISC_LIST(type) struct { type *head, *tail; }
22 #define ISC_LIST_INIT(list) \
23 do { (list).head = NULL; (list).tail = NULL; } while (0)
25 #define ISC_LINK(type) struct { type *prev, *next; }
26 #define ISC_LINK_INIT(elt, link) \
28 (elt)->link.prev = (void *)(-1); \
29 (elt)->link.next = (void *)(-1); \
31 #define ISC_LINK_LINKED(elt, link) ((elt)->link.prev != (void *)(-1))
33 #define ISC_LIST_HEAD(list) ((list).head)
34 #define ISC_LIST_TAIL(list) ((list).tail)
35 #define ISC_LIST_EMPTY(list) ((list).head == NULL)
37 #define ISC_LIST_PREPEND(list, elt, link) \
39 if ((list).head != NULL) \
40 (list).head->link.prev = (elt); \
42 (list).tail = (elt); \
43 (elt)->link.prev = NULL; \
44 (elt)->link.next = (list).head; \
45 (list).head = (elt); \
48 #define ISC_LIST_APPEND(list, elt, link) \
50 if ((list).tail != NULL) \
51 (list).tail->link.next = (elt); \
53 (list).head = (elt); \
54 (elt)->link.prev = (list).tail; \
55 (elt)->link.next = NULL; \
56 (list).tail = (elt); \
59 #define ISC_LIST_UNLINK(list, elt, link) \
61 if ((elt)->link.next != NULL) \
62 (elt)->link.next->link.prev = (elt)->link.prev; \
64 (list).tail = (elt)->link.prev; \
65 if ((elt)->link.prev != NULL) \
66 (elt)->link.prev->link.next = (elt)->link.next; \
68 (list).head = (elt)->link.next; \
69 (elt)->link.prev = (void *)(-1); \
70 (elt)->link.next = (void *)(-1); \
73 #define ISC_LIST_PREV(elt, link) ((elt)->link.prev)
74 #define ISC_LIST_NEXT(elt, link) ((elt)->link.next)
76 #define ISC_LIST_INSERTBEFORE(list, before, elt, link) \
78 if ((before)->link.prev == NULL) \
79 ISC_LIST_PREPEND(list, elt, link); \
81 (elt)->link.prev = (before)->link.prev; \
82 (before)->link.prev = (elt); \
83 (elt)->link.prev->link.next = (elt); \
84 (elt)->link.next = (before); \
88 #define ISC_LIST_INSERTAFTER(list, after, elt, link) \
90 if ((after)->link.next == NULL) \
91 ISC_LIST_APPEND(list, elt, link); \
93 (elt)->link.next = (after)->link.next; \
94 (after)->link.next = (elt); \
95 (elt)->link.next->link.prev = (elt); \
96 (elt)->link.prev = (after); \
100 #define ISC_LIST_APPENDLIST(list1, list2, link) \
102 if (ISC_LIST_EMPTY(list1)) \
104 else if (!ISC_LIST_EMPTY(list2)) { \
105 (list1).tail->link.next = (list2).head; \
106 (list2).head->link.prev = (list1).tail; \
107 (list1).tail = (list2).tail; \
108 (list2).head = NULL; \
109 (list2).tail = NULL; \
113 #define ISC_LIST_ENQUEUE(list, elt, link) ISC_LIST_APPEND(list, elt, link)
114 #define ISC_LIST_DEQUEUE(list, elt, link) ISC_LIST_UNLINK(list, elt, link)
116 #endif /* ISC_LIST_H */