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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* To use these macros you must have a structure containing a next and
25 /* hook into the front of the list */
26 #define DLIST_ADD(list, p) \
30 (p)->next = (p)->prev = NULL; \
39 /* remove an element from a list - element doesn't have to be in list. */
40 #define DLIST_REMOVE(list, p) \
42 if ((p) == (list)) { \
44 if (list) (list)->prev = NULL; \
46 if ((p)->prev) (p)->prev->next = (p)->next; \
47 if ((p)->next) (p)->next->prev = (p)->prev; \
49 if ((p) && ((p) != (list))) (p)->next = (p)->prev = NULL; \
52 /* promote an element to the top of the list */
53 #define DLIST_PROMOTE(list, p) \
55 DLIST_REMOVE(list, p); \
59 /* hook into the end of the list - needs a tmp pointer */
60 #define DLIST_ADD_END(list, p, type) \
64 (p)->next = (p)->prev = NULL; \
67 for (tmp = (list); tmp->next; tmp = tmp->next) ; \
74 /* demote an element to the end of the list, needs a tmp pointer */
75 #define DLIST_DEMOTE(list, p, tmp) \
77 DLIST_REMOVE(list, p); \
78 DLIST_ADD_END(list, p, tmp); \
81 /* concatenate two lists - putting all elements of the 2nd list at the
82 end of the first list */
83 #define DLIST_CONCATENATE(list1, list2, type) \
89 for (tmp = (list1); tmp->next; tmp = tmp->next) ; \
90 tmp->next = (list2); \
91 (list2)->prev = tmp; \
95 #define DLIST_LEN(list, i, type) \
99 for (tmp = (list); tmp; tmp = tmp->next) { (i)++; } \