summaryrefslogtreecommitdiff
path: root/src/commonlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/commonlib')
-rw-r--r--src/commonlib/include/commonlib/helpers.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/commonlib/include/commonlib/helpers.h b/src/commonlib/include/commonlib/helpers.h
index 6ad767e219..0e337c9ce7 100644
--- a/src/commonlib/include/commonlib/helpers.h
+++ b/src/commonlib/include/commonlib/helpers.h
@@ -4,14 +4,18 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1UL)
+#define ALIGN(x,a) __ALIGN_MASK(x,(__typeof__(x))(a)-1UL)
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
#define ALIGN_UP(x,a) ALIGN((x),(a))
-#define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1UL))
-#define IS_ALIGNED(x,a) (((x) & ((typeof(x))(a)-1UL)) == 0)
+#define ALIGN_DOWN(x,a) ((x) & ~((__typeof__(x))(a)-1UL))
+#define IS_ALIGNED(x,a) (((x) & ((__typeof__(x))(a)-1UL)) == 0)
+#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
#define ABS(a) (((a) < 0) ? (-(a)) : (a))
#define CEIL_DIV(a, b) (((a) + (b) - 1) / (b))
#define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
@@ -27,7 +31,9 @@
#define MHz (1000 * KHz)
#define GHz (1000 * MHz)
+#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
#if !defined(__clang__)
#define check_member(structure, member, offset) _Static_assert( \
@@ -45,7 +51,7 @@
*
*/
#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif /* COMMONLIB_HELPERS_H */