summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2015-10-01 14:20:57 -0500
committerAaron Durbin <adurbin@chromium.org>2015-10-02 12:15:47 +0000
commit7ffcc0be63bc8f253c9d4d971ef75be19038963e (patch)
tree61069d1eb61fc61309e2654941240913af4eb4bc
parent04ebf598de6d8b8152c99ebe181de084e0b5b242 (diff)
commonlib/helpers.h: handle interaction with other environments
There are compiler settings and interactions with other header files that should be handled. First use __typeof__ instead of typeof because 'std' modes don't accept typeof. The __typeof__ variant works equally well on clang. The other change is to guard the helper macros so as not to trigger redefinition errors. BUG=chrome-os-partner:44827 BRANCH=None TEST=Built cbfstool including commonlib/helpers.h Change-Id: I58890477cb17df14a9fa8b7af752a7c70769cf36 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/11773 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
-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 */