From 0373e754d62aae0a5052a1eded4b9c988f7f8095 Mon Sep 17 00:00:00 2001 From: Bosko Milekic Date: Wed, 13 Aug 2003 18:37:25 +0000 Subject: [PATCH] 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. --- sys/sys/queue.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/sys/queue.h b/sys/sys/queue.h index 63012d47da07..a06f0847b12d 100644 --- a/sys/sys/queue.h +++ b/sys/sys/queue.h @@ -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)