From 194e28a4c63435c68893e90e33b61890fc09773d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 5 Jan 2025 08:41:07 -0600 Subject: [PATCH] More portabable endianness checking. --- lib/portability.h | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/lib/portability.h b/lib/portability.h index a62a0cb9..324ddc81 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -128,49 +128,25 @@ void *memmem(const void *haystack, size_t haystack_length, // Work out how to do endianness +#define IS_LITTLE_ENDIAN (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define IS_BIG_ENDIAN (!IS_LITTLE_ENDIAN) + #ifdef __APPLE__ #include - -#ifdef __BIG_ENDIAN__ -#define IS_BIG_ENDIAN 1 -#else -#define IS_BIG_ENDIAN 0 -#endif - #define bswap_16(x) OSSwapInt16(x) #define bswap_32(x) OSSwapInt32(x) #define bswap_64(x) OSSwapInt64(x) - #elif defined(__FreeBSD__) || defined(__OpenBSD__) - #include - -#if _BYTE_ORDER == _BIG_ENDIAN -#define IS_BIG_ENDIAN 1 -#else -#define IS_BIG_ENDIAN 0 -#endif - #define bswap_16(x) bswap16(x) #define bswap_32(x) bswap32(x) #define bswap_64(x) bswap64(x) - #else - #include -#include - -#if __BYTE_ORDER == __BIG_ENDIAN -#define IS_BIG_ENDIAN 1 -#else -#define IS_BIG_ENDIAN 0 -#endif - #endif #if IS_BIG_ENDIAN -#define IS_LITTLE_ENDIAN 0 #define SWAP_BE16(x) (x) #define SWAP_BE32(x) (x) #define SWAP_BE64(x) (x) @@ -178,7 +154,6 @@ void *memmem(const void *haystack, size_t haystack_length, #define SWAP_LE32(x) bswap_32(x) #define SWAP_LE64(x) bswap_64(x) #else -#define IS_LITTLE_ENDIAN 1 #define SWAP_BE16(x) bswap_16(x) #define SWAP_BE32(x) bswap_32(x) #define SWAP_BE64(x) bswap_64(x) -- 2.39.5