summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabiano Fidêncio <fidencio@redhat.com>2017-03-21 20:56:38 +0100
committerJakub Hrozek <jhrozek@redhat.com>2017-03-29 14:00:17 +0200
commit34228050af1e25706f61ec9df648852284b61c2b (patch)
treed4e7042066e9e2da3a1325c38ed4babffaa1256f
parentfb81f337b68c85471c3f5140850dccf549a2d0ac (diff)
downloadsssd-34228050af1e25706f61ec9df648852284b61c2b.tar.gz
sssd-34228050af1e25706f61ec9df648852284b61c2b.tar.xz
sssd-34228050af1e25706f61ec9df648852284b61c2b.zip
DLINKLIST: Add DLIST_FOR_EACH_SAFE macro
This macro, as DLIST_FOR_EACH, iterates over the whole list. The main difference between both is that in the _SAFE version the pointer to the next list node is stored, allowing us to delete the current node safely. Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> Reviewed-by: Sumit Bose <sbose@redhat.com> Reviewed-by: Pavel Březina <pbrezina@redhat.com>
-rw-r--r--src/util/dlinklist.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/util/dlinklist.h b/src/util/dlinklist.h
index 4f6aef830..017c60468 100644
--- a/src/util/dlinklist.h
+++ b/src/util/dlinklist.h
@@ -147,4 +147,9 @@ do { \
#define DLIST_FOR_EACH(p, list) \
for ((p) = (list); (p) != NULL; (p) = (p)->next)
+#define DLIST_FOR_EACH_SAFE(p, q, list) \
+ for ((p) = (list), (q) = (p) != NULL ? (p)->next : NULL; \
+ (p) != NULL; \
+ (p) = (q), (q) = (p) != NULL ? (p)->next : NULL)
+
#endif /* _DLINKLIST_H */