libubox: tests: add more blobmsg/json test cases
[project/libubox.git] / utils.h
diff --git a/utils.h b/utils.h
index 6a53b3f5d42595fe1714fc352cc8c85aab5419c4..5c53cc0260d39b00e9bec1a8062356904e0060b1 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -19,6 +19,7 @@
 #ifndef __LIBUBOX_UTILS_H
 #define __LIBUBOX_UTILS_H
 
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <stdint.h>
@@ -125,14 +126,39 @@ int clock_gettime(int type, struct timespec *tv);
        (sizeof(int) == sizeof(*(1 ? ((void*)((long)(x) * 0l)) : (int*)1)))
 
 #define __eval_once(func, x)                                           \
-       ({ typeof(x) __x = x; func(__x); })
+       ({ __typeof__(x) __x = x; func(__x); })
 
+#ifdef __cplusplus
+/*
+ * g++ does not support __builtin_choose_expr, so always use __eval_once.
+ * Unfortunately this means that the byte order functions can't be used
+ * as a constant expression anymore
+ */
+#define __eval_safe(func, x) __eval_once(func, x)
+#else
 #define __eval_safe(func, x)                                           \
        __builtin_choose_expr(__is_constant(x),                         \
                              func(x), __eval_once(func, x))
+#endif
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 
+#define const_cpu_to_be64(x) __constant_swap64(x)
+#define const_cpu_to_be32(x) __constant_swap32(x)
+#define const_cpu_to_be16(x) __constant_swap16(x)
+
+#define const_be64_to_cpu(x) __constant_swap64(x)
+#define const_be32_to_cpu(x) __constant_swap32(x)
+#define const_be16_to_cpu(x) __constant_swap16(x)
+
+#define const_cpu_to_le64(x) (x)
+#define const_cpu_to_le32(x) (x)
+#define const_cpu_to_le16(x) (x)
+
+#define const_le64_to_cpu(x) (x)
+#define const_le32_to_cpu(x) (x)
+#define const_le16_to_cpu(x) (x)
+
 #define cpu_to_be64(x) __eval_safe(__constant_swap64, x)
 #define cpu_to_be32(x) __eval_safe(__constant_swap32, x)
 #define cpu_to_be16(x) __eval_safe(__constant_swap16, x)
@@ -151,6 +177,22 @@ int clock_gettime(int type, struct timespec *tv);
 
 #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
 
+#define const_cpu_to_le64(x) __constant_swap64(x)
+#define const_cpu_to_le32(x) __constant_swap32(x)
+#define const_cpu_to_le16(x) __constant_swap16(x)
+
+#define const_le64_to_cpu(x) __constant_swap64(x)
+#define const_le32_to_cpu(x) __constant_swap32(x)
+#define const_le16_to_cpu(x) __constant_swap16(x)
+
+#define const_cpu_to_be64(x) (x)
+#define const_cpu_to_be32(x) (x)
+#define const_cpu_to_be16(x) (x)
+
+#define const_be64_to_cpu(x) (x)
+#define const_be32_to_cpu(x) (x)
+#define const_be16_to_cpu(x) (x)
+
 #define cpu_to_le64(x) __eval_safe(__constant_swap64, x)
 #define cpu_to_le32(x) __eval_safe(__constant_swap32, x)
 #define cpu_to_le16(x) __eval_safe(__constant_swap16, x)
@@ -211,5 +253,6 @@ static inline unsigned long cbuf_size(int order)
 
 void *cbuf_alloc(unsigned int order);
 void cbuf_free(void *ptr, unsigned int order);
+int mkdir_p(char *dir, mode_t mask);
 
 #endif