From c81b768ae551c035afc4cec0295a6c1551342452 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 11 Dec 2015 16:30:52 +0000 Subject: [PATCH] Improve and simplify endiannes detection --- config.h.in | 54 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/config.h.in b/config.h.in index 0f9e063dc..6615deadf 100644 --- a/config.h.in +++ b/config.h.in @@ -126,33 +126,43 @@ #cmakedefine WITH_SYSTEM_HIREDIS 1 /* Detect endiannes */ - #ifdef HAVE_ENDIAN_H + +#ifdef HAVE_ENDIAN_H #include - #else - #ifdef HAVE_SYS_ENDIAN_H +#elif defined(HAVE_SYS_ENDIAN_H) #include - #else - #ifdef HAVE_MACHINE_ENDIAN_H +#elif defined(HAVE_MACHINE_ENDIAN_H) #include - #else +#endif + +#ifndef BYTE_ORDER + +#ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN 1234 +#endif +#ifndef BIG_ENDIAN #define BIG_ENDIAN 4321 - #if defined(i386) || defined(__i386) || defined(__amd64) || \ - defined(BIT_ZERO_ON_RIGHT) || defined(__x86__) - #define BYTE_ORDER LITTLE_ENDIAN - #endif - - #if defined(__sparc) || defined(__sparc__) || defined(__powerpc__) - #define BYTE_ORDER BIG_ENDIAN - #endif +#endif - #endif /* HAVE_MACHINE_ENDIAN_H */ - #endif /* HAVE_SYS_ENDIAN_H */ - #endif /* HAVE_ENDIAN_H */ +#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \ + defined(__BIG_ENDIAN__) || \ + defined(__ARMEB__) || \ + defined(__THUMBEB__) || \ + defined(__AARCH64EB__) || \ + defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) +#define BYTE_ORDER BIG_ENDIAN +#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \ + defined(__LITTLE_ENDIAN__) || \ + defined(__ARMEL__) || \ + defined(__THUMBEL__) || \ + defined(__AARCH64EL__) || \ + defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) +#define BYTE_ORDER LITTLE_ENDIAN +#else +#error "I don't know what architecture this is!" +#endif - #if !defined(BYTE_ORDER) - # error "Undefined or unknown BYTE_ORDER" - #endif +#endif /* BYTE_ORDER */ /* Configure allocator */ #define uthash_malloc(sz) g_slice_alloc(sz) @@ -227,6 +237,10 @@ #include #endif +#ifdef HAVE_STRINGS_H +#include +#endif + #include #include -- 2.39.5