summaryrefslogtreecommitdiffstats
path: root/include/osmocom
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-05-15 11:44:39 +0200
committerHarald Welte <laforge@gnumonks.org>2017-05-15 13:01:01 +0200
commit054667fe15434e7e467311c7213b50f849aecc79 (patch)
tree8b43e8441d73fec119dee80025cf38c510440dd6 /include/osmocom
parentb93ce5afec0a79068afa12718755724b6cc91db0 (diff)
endian.h: Make it work on 'bare iron' builds (and possibly more platforms)
We can use __BYTE_ORDER__ which seems to be defined by both gcc and clang/llvm. Change-Id: Id6821c99e88242126d9697099b1dd92c6212526a
Diffstat (limited to 'include/osmocom')
-rw-r--r--include/osmocom/core/endian.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/include/osmocom/core/endian.h b/include/osmocom/core/endian.h
index ae133c39..621f34e2 100644
--- a/include/osmocom/core/endian.h
+++ b/include/osmocom/core/endian.h
@@ -34,7 +34,7 @@
#else
#error "Unknown endian"
#endif
-#else
+#elif defined(__linux__)
#include <endian.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define OSMO_IS_LITTLE_ENDIAN 1
@@ -45,5 +45,17 @@
#else
#error "Unknown endian"
#endif
+#else
+ /* let's try to rely on the compiler. GCC and CLANG/LLVM seem
+ * to support this ... */
+ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ #define OSMO_IS_LITTLE_ENDIAN 1
+ #define OSMO_IS_BIG_ENDIAN 0
+ #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ #define OSMO_IS_LITTLE_ENDIAN 0
+ #define OSMO_IS_BIG_ENDIAN 1
+ #else
+ #error "Unknown endian"
+ #endif
#endif