From 2438a024dfd09c8f3daf814b9d1c6936769501aa Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Fri, 19 Jun 2020 17:55:07 -0400 Subject: [PATCH] Introduce list_for_each utility for iterating over list_t --- include/list.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/list.h b/include/list.h index 895f6cc01..ce23f1eed 100644 --- a/include/list.h +++ b/include/list.h @@ -27,6 +27,11 @@ void list_swap(list_t *list, int src, int dest); // move item to end of list void list_move_to_end(list_t *list, void *item); +#define list_for_each(e, list) \ + for (__typeof__(e) *p = (__typeof__(e) *) (list)->items, (e) = *p; \ + (void **) p < ((list)->items + (list)->length); \ + p++, (e) = *p) + /* Calls `free` for each item in the list, then frees the list. * Do not use this to free lists of primitives or items that require more * complicated deallocation code.