summaryrefslogtreecommitdiff
path: root/src/config.h
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-12-11 17:01:00 +0100
committerantirez <antirez@gmail.com>2012-12-11 17:01:00 +0100
commit705874e31db0196d8e1b23a28e8265dbdd2dc136 (patch)
tree68919d1d0f8b07490019d7a346881e8d5b5a084f /src/config.h
parentbf0852e5ed56dfbe32e19d926f8d5cc76f750cc8 (diff)
downloadredis-705874e31db0196d8e1b23a28e8265dbdd2dc136.tar.gz
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.
Diffstat (limited to 'src/config.h')
-rw-r--r--src/config.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/config.h b/src/config.h
index 97c599745..472f10a3a 100644
--- a/src/config.h
+++ b/src/config.h
@@ -139,13 +139,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)
@@ -164,5 +178,4 @@
#endif
#endif
-
#endif