From c695a6a774a12fef5b2df9a25d95940e311e87f2 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 15 Nov 2020 16:37:35 +0100 Subject: [PATCH] tupperware: list: add FOREACH_ENTRY macro --- include/tupperware/list.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/tupperware/list.h b/include/tupperware/list.h index 1cec749..8d94b0f 100644 --- a/include/tupperware/list.h +++ b/include/tupperware/list.h @@ -26,6 +26,15 @@ struct list { (Cur); \ (Cur) = ((Cur)->next == (List).head ? NULL : (Cur)->next)) +#define LIST_FOREACH_ENTRY(Type, Field, List, Cur) \ + for (Type *Cur = (List).head == NULL \ + ? NULL \ + : CONTAINER_OF(Type, Field, (List).head); \ + (Cur); \ + (Cur) = ((Cur)->Field.next == (List).head \ + ? NULL \ + : CONTAINER_OF(Type, Field, (Cur)->Field.next))) + typedef int (*list_cmp_f)(const struct list_node *lhs, const struct list_node *rhs, void *cookie);