Skip to content

Commit

Permalink
list: add the macro LIST_FOREACH_SAFE to support modification during …
Browse files Browse the repository at this point in the history
…linked list traversal
  • Loading branch information
jobo-zt committed Oct 17, 2024
1 parent 2a9fdae commit 1d5c4a6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/re_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ static inline bool list_isempty(const struct list *list)
#define LIST_FOREACH(list, le) \
for ((le) = list_head((list)); (le); (le) = (le)->next)

#define LIST_FOREACH_SAFE(list, le, n) \
for ((le) = list_head((list)), (n) = (le) ? (le)->next : NULL; (le); \
(le) = (n), (n) = (le) ? (le)->next : NULL)

/**
* Move element to another linked list
Expand Down

0 comments on commit 1d5c4a6

Please sign in to comment.