Browse Source

Provide backports of uthash LL_{PREPEND,FOREACH{,_SAFE}}2 (only added in 1.9.7, not yet in major distros)

Luke Dashjr 12 years ago
parent
commit
c648a406e5
2 changed files with 19 additions and 0 deletions
  1. 18 0
      compat.h
  2. 1 0
      lowlevel.c

+ 18 - 0
compat.h

@@ -22,6 +22,24 @@
 #define unix
 #endif
 
+#if defined(LL_FOREACH) && !defined(LL_FOREACH2)
+
+// Missing from uthash before 1.9.7
+
+#define LL_FOREACH2(head,el,next)                                                              \
+    for(el=head;el;el=(el)->next)
+
+#define LL_FOREACH_SAFE2(head,el,tmp,next)                                                     \
+  for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
+
+#define LL_PREPEND2(head,add,next)                                                             \
+do {                                                                                           \
+  (add)->next = head;                                                                          \
+  head = add;                                                                                  \
+} while (0)
+
+#endif
+
 #ifdef WIN32
 #include <errno.h>
 #include <fcntl.h>

+ 1 - 0
lowlevel.c

@@ -15,6 +15,7 @@
 
 #include <utlist.h>
 
+#include "compat.h"
 #include "logging.h"
 #include "lowlevel.h"