X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fendian%2Fendian.h;h=3753f49003df8d5d31208ab5b154ebe375d7e696;hp=dc9f62e646df471d3341cedd6db2f5e2928cff36;hb=696c9b68f6334835f13037a83dd5a11c1c8129c7;hpb=6b8e498bd74a39afd2da684b93bbba783aa11b18 diff --git a/ccan/endian/endian.h b/ccan/endian/endian.h index dc9f62e6..3753f490 100644 --- a/ccan/endian/endian.h +++ b/ccan/endian/endian.h @@ -103,12 +103,29 @@ 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 +#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 + #ifdef __CHECKER__ /* sparse needs forcing to remove bitwise attribute from ccan/short_types */ @@ -279,7 +296,6 @@ static inline uint16_t le16_to_cpu(leint16_t le_val) */ static inline beint64_t cpu_to_be64(uint64_t native) { - return ((ENDIAN_CAST beint64_t)BSWAP_64(native)); return CPU_TO_BE64(native); }