]>
git.ipfire.org Git - thirdparty/systemd.git/blob - list.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
6 /* The head of the linked list. Use this in the structure that shall
7 * contain the head of the linked list */
8 #define LIST_HEAD(t,name) \
11 /* The pointers in the linked list's items. Use this in the item structure */
12 #define LIST_FIELDS(t) \
15 /* Initialize the list's head */
16 #define LIST_HEAD_INIT(t,item) \
18 (item) = (t*) NULL; } \
21 /* Initialize a list item */
22 #define LIST_INIT(t,item) \
26 _item->prev = _item->next = NULL; \
29 /* Prepend an item to the list */
30 #define LIST_PREPEND(t,head,item) \
32 t **_head = &(head), *_item = (item); \
34 if ((_item->next = *_head)) \
35 _item->next->prev = _item; \
40 /* Remove an item from the list */
41 #define LIST_REMOVE(t,head,item) \
43 t **_head = &(head), *_item = (item); \
46 _item->next->prev = _item->prev; \
48 _item->prev->next = _item->next; \
50 assert(*_head == _item); \
51 *_head = _item->next; \
53 _item->next = _item->prev = NULL; \
56 /* Find the head of the list */
57 #define LIST_FIND_HEAD(t,item,head) \
59 t **_head = (head), *_item = (item); \
62 while ((*_head)->prev) \
63 *_head = (*_head)->prev; \
66 /* Insert an item after another one (a = where, b = what) */
67 #define LIST_INSERT_AFTER(t,head,a,b) \
69 t **_head = &(head), *_a = (a), *_b = (b); \
72 if ((_b->next = *_head)) \
73 _b->next->prev = _b; \
77 if ((_b->next = _a->next)) \
78 _b->next->prev = _b; \
84 #define LIST_FOREACH(i,head) \
85 for (i = (head); i; i = i->next)
87 #define LIST_FOREACH_SAFE(i,n,head) \
88 for (i = (head); i && ((n = i->next), 1); i = n)