changeset 16296:bafcb428167b

liblib: Added DLLIST2_INSERT_AFTER_FULL() For inserting a new element in a doubly-linked list after an existing element.
author Stephan Bosch <stephan@rename-it.nl>
date Wed, 17 Apr 2013 18:47:36 +0300
parents cc0dd0d79952
children 61e567c7fdd7
files src/lib/llist.h
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/llist.h	Wed Apr 17 18:44:52 2013 +0300
+++ b/src/lib/llist.h	Wed Apr 17 18:47:36 2013 +0300
@@ -48,6 +48,18 @@
 #define DLLIST2_APPEND(head, tail, item) \
 	DLLIST2_APPEND_FULL(head, tail, item, prev, next)
 
+#define DLLIST2_INSERT_AFTER_FULL(head, tail, after, item, prev, next) \
+	STMT_START { \
+	(item)->prev = (after); \
+	(item)->next = (after)->next; \
+	(after)->next = (item); \
+	if (*(tail) == (after)) \
+		*(tail) = (item); \
+	} STMT_END
+
+#define DLLIST2_INSERT_AFTER(head, tail, after, item) \
+	DLLIST2_INSERT_AFTER_FULL(head, tail, after, item, prev, next)
+
 #define DLLIST2_REMOVE_FULL(head, tail, item, prev, next) STMT_START { \
 	if ((item)->prev == NULL) \
 		*(head) = (item)->next; \