From 308beb85fed82a210f32c2770abf69962caff2eb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Oct 2019 10:05:50 +0200 Subject: [PATCH] shared: add nm_c_list_for_each_entry_prev() helper macro It's non-trivial to get this right. Add the macro for iterating the list in reverse. --- shared/nm-glib-aux/nm-c-list.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared/nm-glib-aux/nm-c-list.h b/shared/nm-glib-aux/nm-c-list.h index 7a6e8ccaf2..256dda74fb 100644 --- a/shared/nm-glib-aux/nm-c-list.h +++ b/shared/nm-glib-aux/nm-c-list.h @@ -17,6 +17,12 @@ _what && c_list_contains (list, &_what->member); \ }) +/* iterate over the list backwards. */ +#define nm_c_list_for_each_entry_prev(_iter, _list, _m) \ + for (_iter = c_list_entry ((_list)->prev, __typeof__ (*_iter), _m); \ + &(_iter)->_m != (_list); \ + _iter = c_list_entry ((_iter)->_m.prev, __typeof__ (*_iter), _m)) + /*****************************************************************************/ typedef struct {