1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 09:56:51 +03:00

shared/list: add LIST_APPEND

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2015-01-09 13:34:01 -05:00
parent 33e1e5a756
commit 502f1733e3
2 changed files with 32 additions and 0 deletions

View File

@ -55,6 +55,14 @@
*_head = _item; \ *_head = _item; \
} while(false) } 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 */ /* Remove an item from the list */
#define LIST_REMOVE(name,head,item) \ #define LIST_REMOVE(name,head,item) \
do { \ do { \

View File

@ -105,5 +105,29 @@ int main(int argc, const char *argv[]) {
LIST_REMOVE(item, head, &items[3]); LIST_REMOVE(item, head, &items[3]);
assert_se(LIST_JUST_US(item, &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; return 0;
} }