endian: fix compilation with musl libc.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 10 May 2018 02:25:59 +0000 (11:55 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 10 May 2018 02:25:59 +0000 (11:55 +0930)
It defines __BYTE_ORDER to __BYTE_ORDER__; gcc complains when we define
it to something else.  Let it be already defined, but check that the
value is what we expect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/endian/endian.h

index 6732e8aa8193f11a8e131a65bee1fa87fbe8495e..3753f49003df8d5d31208ab5b154ebe375d7e696 100644 (file)
@@ -113,9 +113,17 @@ static inline uint64_t bswap_64(uint64_t val)
 #elif HAVE_LITTLE_ENDIAN && HAVE_BIG_ENDIAN
 #error "Can't compile for both big and little endian."
 #elif HAVE_LITTLE_ENDIAN
+#ifndef __BYTE_ORDER
 #define __BYTE_ORDER   __LITTLE_ENDIAN
+#elif __BYTE_ORDER != __LITTLE_ENDIAN
+#error "__BYTE_ORDER already defined, but not equal to __LITTLE_ENDIAN"
+#endif
 #elif HAVE_BIG_ENDIAN
+#ifndef __BYTE_ORDER
 #define __BYTE_ORDER   __BIG_ENDIAN
+#elif __BYTE_ORDER != __BIG_ENDIAN
+#error "__BYTE_ORDER already defined, but not equal to __BIG_ENDIAN"
+#endif
 #endif