summaryrefslogtreecommitdiff
path: root/source3/include
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-09-18 07:52:16 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:51:59 -0500
commit258a465e20e007a30043220367d17ecfc87b4f90 (patch)
treee85402425f7b199bb87fa95537eeb084861b4066 /source3/include
parent8155621d54c7385a60274b30572770bd4f17e504 (diff)
downloadsamba-258a465e20e007a30043220367d17ecfc87b4f90.tar.gz
samba-258a465e20e007a30043220367d17ecfc87b4f90.tar.bz2
samba-258a465e20e007a30043220367d17ecfc87b4f90.zip
r18605: sync dlinklist.h with samba4, that means DLIST_ADD_END()
and DLIST_DEMOTE() now take the type of the tmp pointer not the tmp pointer itself anymore. metze (This used to be commit 2f58645b7094e81dff3734f11aa183ea2ab53d2d)
Diffstat (limited to 'source3/include')
-rw-r--r--source3/include/dlinklist.h60
1 files changed, 41 insertions, 19 deletions
diff --git a/source3/include/dlinklist.h b/source3/include/dlinklist.h
index daec7640e4..f267e77ea6 100644
--- a/source3/include/dlinklist.h
+++ b/source3/include/dlinklist.h
@@ -21,10 +21,13 @@
/* To use these macros you must have a structure containing a next and
prev pointer */
+#ifndef _DLINKLIST_H
+#define _DLINKLIST_H
+
/* hook into the front of the list */
#define DLIST_ADD(list, p) \
-{ \
+do { \
if (!(list)) { \
(list) = (p); \
(p)->next = (p)->prev = NULL; \
@@ -34,11 +37,11 @@
(p)->prev = NULL; \
(list) = (p); \
}\
-}
+} while (0)
/* remove an element from a list - element doesn't have to be in list. */
#define DLIST_REMOVE(list, p) \
-{ \
+do { \
if ((p) == (list)) { \
(list) = (p)->next; \
if (list) (list)->prev = NULL; \
@@ -47,28 +50,29 @@
if ((p)->next) (p)->next->prev = (p)->prev; \
} \
if ((p) != (list)) (p)->next = (p)->prev = NULL; \
-}
+} while (0)
/* promote an element to the top of the list */
#define DLIST_PROMOTE(list, p) \
-{ \
- DLIST_REMOVE(list, p) \
- DLIST_ADD(list, p) \
-}
+do { \
+ DLIST_REMOVE(list, p); \
+ DLIST_ADD(list, p); \
+} while (0)
/* hook into the end of the list - needs a tmp pointer */
-#define DLIST_ADD_END(list, p, tmp) \
-{ \
+#define DLIST_ADD_END(list, p, type) \
+do { \
if (!(list)) { \
(list) = (p); \
(p)->next = (p)->prev = NULL; \
} else { \
- for ((tmp) = (list); (tmp)->next; (tmp) = (tmp)->next) ; \
- (tmp)->next = (p); \
+ type tmp; \
+ for (tmp = (list); tmp->next; tmp = tmp->next) ; \
+ tmp->next = (p); \
(p)->next = NULL; \
- (p)->prev = (tmp); \
+ (p)->prev = tmp; \
} \
-}
+} while (0)
/* insert 'p' after the given element 'el' in a list. If el is NULL then
this is the same as a DLIST_ADD() */
@@ -84,9 +88,27 @@ do { \
}\
} while (0)
-/* demote an element to the top of the list, needs a tmp pointer */
+/* demote an element to the end of the list, needs a tmp pointer */
#define DLIST_DEMOTE(list, p, tmp) \
-{ \
- DLIST_REMOVE(list, p) \
- DLIST_ADD_END(list, p, tmp) \
-}
+do { \
+ DLIST_REMOVE(list, p); \
+ DLIST_ADD_END(list, p, tmp); \
+} while (0)
+
+/* concatenate two lists - putting all elements of the 2nd list at the
+ end of the first list */
+#define DLIST_CONCATENATE(list1, list2, type) \
+do { \
+ if (!(list1)) { \
+ (list1) = (list2); \
+ } else { \
+ type tmp; \
+ for (tmp = (list1); tmp->next; tmp = tmp->next) ; \
+ tmp->next = (list2); \
+ if (list2) { \
+ (list2)->prev = tmp; \
+ } \
+ } \
+} while (0)
+
+#endif /* _DLINKLIST_H */