[PATCH] libosmocore[master]: endian.h: Make it work on 'bare iron' builds (and possibly m...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon May 15 11:14:18 UTC 2017


Review at  https://gerrit.osmocom.org/2622

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
---
M include/osmocom/core/endian.h
1 file changed, 13 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/22/2622/1

diff --git a/include/osmocom/core/endian.h b/include/osmocom/core/endian.h
index ae133c3..621f34e 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
 

-- 
To view, visit https://gerrit.osmocom.org/2622
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id6821c99e88242126d9697099b1dd92c6212526a
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list