From: antirez Date: Tue, 11 Dec 2012 16:01:00 +0000 (+0100) Subject: Fix config.h endianess detection to work on Linux / PPC64. X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/d64a9cf514d2101fbad002b8721c9fe1176916ac Fix config.h endianess detection to work on Linux / PPC64. Config.h performs endianess detection including OS-specific headers to define the endianess macros, or when this is not possible, checking the processor type via ifdefs. Sometimes when the OS-specific macro is included, only __BYTE_ORDER is defined, while BYTE_ORDER remains undefined. There is code at the end of config.h endianess detection in order to define the macros without the underscore, but it was not working correctly. This commit fixes endianess detection fixing Redis on Linux / PPC64 and possibly other systems. --- diff --git a/src/config.h b/src/config.h index db33407c..b5c8284a 100644 --- a/src/config.h +++ b/src/config.h @@ -137,13 +137,27 @@ #endif /* BSD */ #endif /* BYTE_ORDER */ -#if defined(__BYTE_ORDER) && !defined(BYTE_ORDER) +/* Sometimes after including an OS-specific header that defines the + * endianess we end with __BYTE_ORDER but not with BYTE_ORDER that is what + * the Redis code uses. In this case let's define everything without the + * underscores. */ +#ifndef BYTE_ORDER +#ifdef __BYTE_ORDER +#if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#endif +#ifndef BIG_ENDIAN +#define BIG_ENDIAN __BIG_ENDIAN +#endif #if (__BYTE_ORDER == __LITTLE_ENDIAN) #define BYTE_ORDER LITTLE_ENDIAN #else #define BYTE_ORDER BIG_ENDIAN #endif #endif +#endif +#endif #if !defined(BYTE_ORDER) || \ (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN) @@ -162,5 +176,4 @@ #endif #endif - #endif diff --git a/src/endianconv.h b/src/endianconv.h index f76e0e6b..7afe61c6 100644 --- a/src/endianconv.h +++ b/src/endianconv.h @@ -33,6 +33,7 @@ #ifndef __ENDIANCONV_H #define __ENDIANCONV_H +#include "config.h" #include void memrev16(void *p);