util: add ARRAY_FOR_EACH helper
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 6 Dec 2013 04:35:22 +0000 (14:35 +1000)
committerJonas Ådahl <jadahl@gmail.com>
Sat, 21 Dec 2013 11:09:55 +0000 (12:09 +0100)
Requires c99, but that's the future.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/libinput-util.h

index 45549e0..381a0d4 100644 (file)
@@ -70,6 +70,8 @@ int list_empty(const struct list *list);
             tmp = container_of(pos->member.next, tmp, member))
 
 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
+#define ARRAY_FOR_EACH(_arr, _elem) \
+       for (int i = 0; (_elem = &_arr[i]) && i < ARRAY_LENGTH(_arr); i++)
 
 /*
  * This fixed point implementation is a verbatim copy from wayland-util.h from