chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
efivars: use greedy_realloc
[elogind.git]
/
src
/
shared
/
list.h
diff --git
a/src/shared/list.h
b/src/shared/list.h
index 96d6237974726693512b71cbc12c12e9df7bcf4e..2939216adb60ef0aa43015421d3c9631de206a6e 100644
(file)
--- a/
src/shared/list.h
+++ b/
src/shared/list.h
@@
-31,23
+31,23
@@
t *name##_next, *name##_prev
/* Initialize the list's head */
t *name##_next, *name##_prev
/* Initialize the list's head */
-#define LIST_HEAD_INIT(
t,head)
\
+#define LIST_HEAD_INIT(
head)
\
do { \
(head) = NULL; } \
while(false)
/* Initialize a list item */
do { \
(head) = NULL; } \
while(false)
/* Initialize a list item */
-#define LIST_INIT(
t,name,item)
\
+#define LIST_INIT(
name,item)
\
do { \
do { \
- t
*_item = (item);
\
+ t
ypeof(*(item)) *_item = (item);
\
assert(_item); \
_item->name##_prev = _item->name##_next = NULL; \
} while(false)
/* Prepend an item to the list */
assert(_item); \
_item->name##_prev = _item->name##_next = NULL; \
} while(false)
/* Prepend an item to the list */
-#define LIST_PREPEND(
t,name,head,item)
\
+#define LIST_PREPEND(
name,head,item)
\
do { \
do { \
- t
**_head = &(head), *_item = (item);
\
+ t
ypeof(*(head)) **_head = &(head), *_item = (item);
\
assert(_item); \
if ((_item->name##_next = *_head)) \
_item->name##_next->name##_prev = _item; \
assert(_item); \
if ((_item->name##_next = *_head)) \
_item->name##_next->name##_prev = _item; \
@@
-55,10
+55,18
@@
*_head = _item; \
} while(false)
*_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 */
/* Remove an item from the list */
-#define LIST_REMOVE(
t,name,head,item)
\
+#define LIST_REMOVE(
name,head,item)
\
do { \
do { \
- t
**_head = &(head), *_item = (item);
\
+ t
ypeof(*(head)) **_head = &(head), *_item = (item);
\
assert(_item); \
if (_item->name##_next) \
_item->name##_next->name##_prev = _item->name##_prev; \
assert(_item); \
if (_item->name##_next) \
_item->name##_next->name##_prev = _item->name##_prev; \
@@
-72,29
+80,35
@@
} while(false)
/* Find the head of the list */
} while(false)
/* Find the head of the list */
-#define LIST_FIND_HEAD(
t,name,item,head)
\
+#define LIST_FIND_HEAD(
name,item,head)
\
do { \
do { \
- t *_item = (item); \
- assert(_item); \
- while (_item->name##_prev) \
- _item = _item->name##_prev; \
- (head) = _item; \
+ typeof(*(item)) *_item = (item); \
+ if (!_item) \
+ (head) = NULL; \
+ else { \
+ while (_item->name##_prev) \
+ _item = _item->name##_prev; \
+ (head) = _item; \
+ } \
} while (false)
} while (false)
-/* Find the
head
of the list */
-#define LIST_FIND_TAIL(
t,name,item,tail)
\
+/* Find the
tail
of the list */
+#define LIST_FIND_TAIL(
name,item,tail)
\
do { \
do { \
- t *_item = (item); \
- assert(_item); \
- while (_item->name##_next) \
- _item = _item->name##_next; \
- (tail) = _item; \
+ typeof(*(item)) *_item = (item); \
+ if (!_item) \
+ (tail) = NULL; \
+ else { \
+ while (_item->name##_next) \
+ _item = _item->name##_next; \
+ (tail) = _item; \
+ } \
} while (false)
/* Insert an item after another one (a = where, b = what) */
} while (false)
/* Insert an item after another one (a = where, b = what) */
-#define LIST_INSERT_AFTER(
t,name,head,a,b)
\
+#define LIST_INSERT_AFTER(
name,head,a,b)
\
do { \
do { \
- t
**_head = &(head), *_a = (a), *_b = (b);
\
+ t
ypeof(*(head)) **_head = &(head), *_a = (a), *_b = (b);
\
assert(_b); \
if (!_a) { \
if ((_b->name##_next = *_head)) \
assert(_b); \
if (!_a) { \
if ((_b->name##_next = *_head)) \
@@
-124,6
+138,18
@@
#define LIST_FOREACH_AFTER(name,i,p) \
for ((i) = (p)->name##_next; (i); (i) = (i)->name##_next)
#define LIST_FOREACH_AFTER(name,i,p) \
for ((i) = (p)->name##_next; (i); (i) = (i)->name##_next)
+/* Iterate through all the members of the list p is included in, but skip over p */
+#define LIST_FOREACH_OTHERS(name,i,p) \
+ for (({ \
+ (i) = (p); \
+ while ((i) && (i)->name##_prev) \
+ (i) = (i)->name##_prev; \
+ if ((i) == (p)) \
+ (i) = (p)->name##_next; \
+ }); \
+ (i); \
+ (i) = (i)->name##_next == (p) ? (p)->name##_next : (i)->name##_next)
+
/* Loop starting from p->next until p->prev.
p can be adjusted meanwhile. */
#define LIST_LOOP_BUT_ONE(name,i,head,p) \
/* Loop starting from p->next until p->prev.
p can be adjusted meanwhile. */
#define LIST_LOOP_BUT_ONE(name,i,head,p) \