summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shared/list.h8
-rw-r--r--src/test/test-list.c24
2 files changed, 32 insertions, 0 deletions
diff --git a/src/shared/list.h b/src/shared/list.h
index c020f7e936..f0458b54e2 100644
--- a/src/shared/list.h
+++ b/src/shared/list.h
@@ -55,6 +55,14 @@
*_head = _item; \
} while(false)
+/* Append an item to the list */
+#define LIST_APPEND(name,head,item) \
+ do { \
+ typeof(*(head)) *_tail; \
+ LIST_FIND_TAIL(name,head,_tail); \
+ LIST_INSERT_AFTER(name,head,_tail,item); \
+ } while(false)
+
/* Remove an item from the list */
#define LIST_REMOVE(name,head,item) \
do { \
diff --git a/src/test/test-list.c b/src/test/test-list.c
index fa52ad1db8..e9d47f0503 100644
--- a/src/test/test-list.c
+++ b/src/test/test-list.c
@@ -105,5 +105,29 @@ int main(int argc, const char *argv[]) {
LIST_REMOVE(item, head, &items[3]);
assert_se(LIST_JUST_US(item, &items[3]));
+ assert_se(head == NULL);
+
+ for (i = 0; i < ELEMENTSOF(items); i++) {
+ assert_se(LIST_JUST_US(item, &items[i]));
+ LIST_APPEND(item, head, &items[i]);
+ }
+
+ assert_se(!LIST_JUST_US(item, head));
+
+ assert_se(items[0].item_next == &items[1]);
+ assert_se(items[1].item_next == &items[2]);
+ assert_se(items[2].item_next == &items[3]);
+ assert_se(items[3].item_next == NULL);
+
+ assert_se(items[0].item_prev == NULL);
+ assert_se(items[1].item_prev == &items[0]);
+ assert_se(items[2].item_prev == &items[1]);
+ assert_se(items[3].item_prev == &items[2]);
+
+ for (i = 0; i < ELEMENTSOF(items); i++)
+ LIST_REMOVE(item, head, &items[i]);
+
+ assert_se(head == NULL);
+
return 0;
}