endian: Add Glibc like endianess check
authorAkshay Adiga <akshay.adiga@linux.vnet.ibm.com>
Tue, 12 Sep 2017 05:23:13 +0000 (10:53 +0530)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 12 Sep 2017 11:01:45 +0000 (20:31 +0930)
An application built using glibc would expect __BYTE_ORDER to tell if
it should be compiled for BIG_ENDIAN or LITTLE_ENDIAN, whereas ccan uses
HAVE_LITTLE_ENDIAN and HAVE_BIG_ENDIAN for the same purpose.

Hence setting __BYTE_ORDER based on what CCAN provides will no longer
break the applications which check endianness the glibc way.

Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/endian/endian.h

index 0c99cc802db0e0acac0668d11d305fe89b4b5aed..6732e8aa8193f11a8e131a65bee1fa87fbe8495e 100644 (file)
@@ -103,13 +103,22 @@ static inline uint64_t bswap_64(uint64_t val)
 }
 #endif
 
 }
 #endif
 
+/* Needed for Glibc like endiness check */
+#define        __LITTLE_ENDIAN 1234
+#define        __BIG_ENDIAN    4321
+
 /* Sanity check the defines.  We don't handle weird endianness. */
 #if !HAVE_LITTLE_ENDIAN && !HAVE_BIG_ENDIAN
 #error "Unknown endian"
 #elif HAVE_LITTLE_ENDIAN && HAVE_BIG_ENDIAN
 #error "Can't compile for both big and little endian."
 /* Sanity check the defines.  We don't handle weird endianness. */
 #if !HAVE_LITTLE_ENDIAN && !HAVE_BIG_ENDIAN
 #error "Unknown endian"
 #elif HAVE_LITTLE_ENDIAN && HAVE_BIG_ENDIAN
 #error "Can't compile for both big and little endian."
+#elif HAVE_LITTLE_ENDIAN
+#define __BYTE_ORDER   __LITTLE_ENDIAN
+#elif HAVE_BIG_ENDIAN
+#define __BYTE_ORDER   __BIG_ENDIAN
 #endif
 
 #endif
 
+
 #ifdef __CHECKER__
 /* sparse needs forcing to remove bitwise attribute from ccan/short_types */
 #define ENDIAN_CAST __attribute__((force))
 #ifdef __CHECKER__
 /* sparse needs forcing to remove bitwise attribute from ccan/short_types */
 #define ENDIAN_CAST __attribute__((force))