Commit 759ac0f0 authored by Akshay Adiga's avatar Akshay Adiga Committed by Rusty Russell

endian: Add Glibc like endianess check

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: default avatarAkshay Adiga <akshay.adiga@linux.vnet.ibm.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 9728f1d9
......@@ -103,13 +103,22 @@ static inline uint64_t bswap_64(uint64_t val)
}
#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."
#elif HAVE_LITTLE_ENDIAN
#define __BYTE_ORDER __LITTLE_ENDIAN
#elif HAVE_BIG_ENDIAN
#define __BYTE_ORDER __BIG_ENDIAN
#endif
#ifdef __CHECKER__
/* sparse needs forcing to remove bitwise attribute from ccan/short_types */
#define ENDIAN_CAST __attribute__((force))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment