2 Unix SMB/CIFS implementation.
3 some simple double linked list macros
4 Copyright (C) Andrew Tridgell 1998
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 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /* To use these macros you must have a structure containing a next and
27 /* hook into the front of the list */
28 #define DLIST_ADD(list, p) \
32 (p)->next = (p)->prev = NULL; \
41 /* remove an element from a list - element doesn't have to be in list. */
42 #define DLIST_REMOVE(list, p) \
44 if ((p) == (list)) { \
46 if (list) (list)->prev = NULL; \
48 if ((p)->prev) (p)->prev->next = (p)->next; \
49 if ((p)->next) (p)->next->prev = (p)->prev; \
51 if ((p) != (list)) (p)->next = (p)->prev = NULL; \
54 /* promote an element to the top of the list */
55 #define DLIST_PROMOTE(list, p) \
57 DLIST_REMOVE(list, p); \
61 /* hook into the end of the list - needs the entry type */
62 #define DLIST_ADD_END(list, p, type) \
66 (p)->next = (p)->prev = NULL; \
69 for (tmp = (list); tmp->next; tmp = tmp->next) ; \
76 /* insert 'p' after the given element 'el' in a list. If el is NULL then
77 this is the same as a DLIST_ADD() */
78 #define DLIST_ADD_AFTER(list, p, el) \
80 if (!(list) || !(el)) { \
86 if (p->next) p->next->prev = p; \
90 /* demote an element to the end of the list, needs a tmp pointer */
91 #define DLIST_DEMOTE(list, p, tmp) \
93 DLIST_REMOVE(list, p); \
94 DLIST_ADD_END(list, p, tmp); \
97 /* concatenate two lists - putting all elements of the 2nd list at the
98 end of the first list */
99 #define DLIST_CONCATENATE(list1, list2, type) \
105 for (tmp = (list1); tmp->next; tmp = tmp->next) ; \
106 tmp->next = (list2); \
108 (list2)->prev = tmp; \
113 #endif /* _DLINKLIST_H */