]> git.ozlabs.org Git - ccan/blobdiff - ccan/endian/endian.h
endian: fix compilation with musl libc.
[ccan] / ccan / endian / endian.h
index 0c99cc802db0e0acac0668d11d305fe89b4b5aed..3753f49003df8d5d31208ab5b154ebe375d7e696 100644 (file)
@@ -103,12 +103,29 @@ 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
+#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
+#endif
+
 
 #ifdef __CHECKER__
 /* sparse needs forcing to remove bitwise attribute from ccan/short_types */
 
 #ifdef __CHECKER__
 /* sparse needs forcing to remove bitwise attribute from ccan/short_types */