r25068: Older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for every opcode on the
[Samba.git] / source / lib / ldb / include / dlinklist.h
blob3779a4cc61cd8c0bb343375d5c8cec0321d2efea
1 /*
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 2 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
22 prev pointer */
25 /* hook into the front of the list */
26 #define DLIST_ADD(list, p) \
27 do { \
28 if (!(list)) { \
29 (list) = (p); \
30 (p)->next = (p)->prev = NULL; \
31 } else { \
32 (list)->prev = (p); \
33 (p)->next = (list); \
34 (p)->prev = NULL; \
35 (list) = (p); \
37 } while (0)
39 /* remove an element from a list - element doesn't have to be in list. */
40 #ifndef DLIST_REMOVE
41 #define DLIST_REMOVE(list, p) \
42 do { \
43 if ((p) == (list)) { \
44 (list) = (p)->next; \
45 if (list) (list)->prev = NULL; \
46 } else { \
47 if ((p)->prev) (p)->prev->next = (p)->next; \
48 if ((p)->next) (p)->next->prev = (p)->prev; \
49 } \
50 if ((p) && ((p) != (list))) (p)->next = (p)->prev = NULL; \
51 } while (0)
52 #endif
54 /* promote an element to the top of the list */
55 #define DLIST_PROMOTE(list, p) \
56 do { \
57 DLIST_REMOVE(list, p); \
58 DLIST_ADD(list, p); \
59 } while (0)
61 /* hook into the end of the list - needs a tmp pointer */
62 #define DLIST_ADD_END(list, p, type) \
63 do { \
64 if (!(list)) { \
65 (list) = (p); \
66 (p)->next = (p)->prev = NULL; \
67 } else { \
68 type tmp; \
69 for (tmp = (list); tmp->next; tmp = tmp->next) ; \
70 tmp->next = (p); \
71 (p)->next = NULL; \
72 (p)->prev = tmp; \
73 } \
74 } while (0)
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) \
79 do { \
80 if (!(list) || !(el)) { \
81 DLIST_ADD(list, p); \
82 } else { \
83 p->prev = el; \
84 p->next = el->next; \
85 el->next = p; \
86 if (p->next) p->next->prev = p; \
88 } while (0)
90 /* demote an element to the end of the list, needs a tmp pointer */
91 #define DLIST_DEMOTE(list, p, tmp) \
92 do { \
93 DLIST_REMOVE(list, p); \
94 DLIST_ADD_END(list, p, tmp); \
95 } while (0)
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) \
100 do { \
101 if (!(list1)) { \
102 (list1) = (list2); \
103 } else { \
104 type tmp; \
105 for (tmp = (list1); tmp->next; tmp = tmp->next) ; \
106 tmp->next = (list2); \
107 if (list2) { \
108 (list2)->prev = tmp; \
111 } while (0)