Add LIST_FOREACH_SAFE, which is like LIST_FOREACH but allows you

to walk the list and remove the current item and destroy/free it.

Alexander Kabaev will likely do the equivalent for the other list
types, but I just happened to have this one sitting in a local
non-FreeBSD tree already.
This commit is contained in:
Bosko Milekic 2003-08-13 18:37:25 +00:00
parent 5105f9919f
commit 0373e754d6

View File

@ -325,6 +325,13 @@ struct { \
(var); \
(var) = LIST_NEXT((var), field))
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = LIST_FIRST((head)), \
(var) != NULL ? (tvar) = LIST_NEXT((var), field) : NULL; \
(var) != NULL; \
(var) = (tvar), \
(var) != NULL ? (tvar) = LIST_NEXT((var), field) : NULL)
#define LIST_INIT(head) do { \
LIST_FIRST((head)) = NULL; \
} while (0)