Blame SOURCES/0051-DLINKLIST-Add-DLIST_FOR_EACH_SAFE-macro.patch

ecf709
From 8c7c97d1b3af8c99af43dcaff7ae1d9315a03835 Mon Sep 17 00:00:00 2001
ecf709
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
ecf709
Date: Tue, 21 Mar 2017 20:56:38 +0100
ecf709
Subject: [PATCH 51/54] DLINKLIST: Add DLIST_FOR_EACH_SAFE macro
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
This macro, as DLIST_FOR_EACH, iterates over the whole list. The main
ecf709
difference between both is that in the _SAFE version the pointer to the
ecf709
next list node is stored, allowing us to delete the current node safely.
ecf709
ecf709
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
ecf709
ecf709
Reviewed-by: Sumit Bose <sbose@redhat.com>
ecf709
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
ecf709
---
ecf709
 src/util/dlinklist.h | 5 +++++
ecf709
 1 file changed, 5 insertions(+)
ecf709
ecf709
diff --git a/src/util/dlinklist.h b/src/util/dlinklist.h
ecf709
index 4f6aef830e914c22654970081263d43461c1750f..017c60468e66dbec15724d5f4832da412f42136b 100644
ecf709
--- a/src/util/dlinklist.h
ecf709
+++ b/src/util/dlinklist.h
ecf709
@@ -147,4 +147,9 @@ do { \
ecf709
 #define DLIST_FOR_EACH(p, list) \
ecf709
     for ((p) = (list); (p) != NULL; (p) = (p)->next)
ecf709
 
ecf709
+#define DLIST_FOR_EACH_SAFE(p, q, list) \
ecf709
+    for ((p) = (list), (q) = (p) != NULL ? (p)->next : NULL; \
ecf709
+         (p) != NULL; \
ecf709
+         (p) = (q), (q) = (p) != NULL ? (p)->next : NULL)
ecf709
+
ecf709
 #endif /* _DLINKLIST_H */
ecf709
-- 
ecf709
2.9.3
ecf709