summaryrefslogtreecommitdiff
path: root/wayland-util.h
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2010-02-26 10:28:44 -0500
committerKristian Høgsberg <krh@bitplanet.net>2010-02-26 10:28:44 -0500
commita5db589efaedebf2b01a61baa2efc917a7e45d68 (patch)
tree37ff5c71534b0673bf4ce57c7d382c63f2ce3a6d /wayland-util.h
parentd923e9d93b95e1c902dade030ae5af2e80242878 (diff)
Add wl_list_for_each() and simplify some loops
Diffstat (limited to 'wayland-util.h')
-rw-r--r--wayland-util.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/wayland-util.h b/wayland-util.h
index 4c3af5d..0233cb3 100644
--- a/wayland-util.h
+++ b/wayland-util.h
@@ -82,6 +82,15 @@ void wl_list_remove(struct wl_list *elm);
int wl_list_length(struct wl_list *list);
int wl_list_empty(struct wl_list *list);
+#define __container_of(ptr, sample, member) \
+ (void *)((char *)(ptr) - \
+ ((char *)&(sample)->member - (char *)(sample)))
+
+#define wl_list_for_each(pos, head, member) \
+ for (pos = __container_of((head)->next, pos, member); \
+ &pos->member != (head); \
+ pos = __container_of(pos->member.next, pos, member))
+
struct wl_array {
uint32_t size;
uint32_t alloc;