ccan/endian.h: Only define __{BIG,LITTLE}_ENDIAN if undefined.
authorWarner Losh <imp@bsdimp.com>
Fri, 3 May 2024 17:39:42 +0000 (11:39 -0600)
committerDaniel Wagner <wagi@monom.org>
Mon, 6 May 2024 17:22:35 +0000 (19:22 +0200)
When both endian.h and ccan/endian/endian.h are included, we can have
__{BIG,LITTLE}_ENDIAN redefined when compiling with clang on FreeBSD.
Clang and gcc have moved to a predefine for endian orders. glibc defines
these the same as they are defied here, but that's an unsafe assumption
to make. Instead, only define them when __LITTLE_ENDIAN not defined as a
fallback to when the host does not define them in the standard system
headers.

Signed-off-by: Warner Losh <imp@bsdimp.com>
ccan/ccan/endian/endian.h

index 3753f49003df8d5d31208ab5b154ebe375d7e696..ae96b51ed0d5ff994abb742afb7427a384448e64 100644 (file)
@@ -104,8 +104,10 @@ static inline uint64_t bswap_64(uint64_t val)
 #endif
 
 /* Needed for Glibc like endiness check */
+#ifndef __LITTLE_ENDIAN
 #define        __LITTLE_ENDIAN 1234
 #define        __BIG_ENDIAN    4321
+#endif
 
 /* Sanity check the defines.  We don't handle weird endianness. */
 #if !HAVE_LITTLE_ENDIAN && !HAVE_BIG_ENDIAN