<sys/tree.h>: Add RB_FOREACH_* macros from FreeBSD
authorJohn Marino <draco@marino.st>
Sun, 9 Aug 2015 14:37:03 +0000 (16:37 +0200)
committerJohn Marino <draco@marino.st>
Sun, 9 Aug 2015 14:39:56 +0000 (16:39 +0200)
At least one port is using RB_FOREACH* from sys/tree.h (x11-wm/spectrwm)

sys/sys/tree.h

index bf05c78..695a065 100644 (file)
@@ -984,4 +984,29 @@ name##_RB_LOOKUP_##ext (struct name *head, datatype value)         \
             (x) != NULL;                                               \
             (x) = name##_RB_NEXT(x))
 
+#define RB_FOREACH_FROM(x, name, y)                                    \
+       for ((x) = (y);                                                 \
+           ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL);    \
+            (x) = (y))
+
+#define RB_FOREACH_SAFE(x, name, head, y)                              \
+       for ((x) = RB_MIN(name, head);                                  \
+           ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL);    \
+            (x) = (y))
+
+#define RB_FOREACH_REVERSE(x, name, head)                              \
+       for ((x) = RB_MAX(name, head);                                  \
+            (x) != NULL;                                               \
+            (x) = name##_RB_PREV(x))
+
+#define RB_FOREACH_REVERSE_FROM(x, name, y)                            \
+       for ((x) = (y);                                                 \
+           ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL);    \
+            (x) = (y))
+
+#define RB_FOREACH_REVERSE_SAFE(x, name, head, y)                      \
+       for ((x) = RB_MAX(name, head);                                  \
+           ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL);    \
+            (x) = (y))
+
 #endif /* _SYS_TREE_H_ */