aboutsummaryrefslogtreecommitdiffstats
path: root/main/rhash/librhash-byte_order.h-Consult-also-compiler-s-predef.patch
blob: ddaefadaf08900006b7a996827407723c0a2c915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
From cf3c9003487cbf8cc594dbb77e333e1609a1786e Mon Sep 17 00:00:00 2001
From: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date: Thu, 17 Nov 2016 15:57:19 +0100
Subject: [PATCH] librhash/byte_order.h: Consult also compiler's predefined
 macros.

byte_order.h includes <endian.h> only if glibc is used (i.e. __GLIBC__
is defined), but there are other libc implementation that also provide
endian.h, like musl libc for instance.  Generally it's much better and
cleaner to check feature test macros than check for particular
implementation (and that is also why musl libc doesn't define __MUSL__).
Unfortunately I am not aware of feature test macro guaranteeing endian.h
availability.

The simple solution is to add checking for compiler's pre-defined macros
(__BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, __ORDER_LITTLE_ENDIAN__) after
checking macros coming from system headers, i.e. <endian.h> in this case
(__BYTE_ORDER, __BIG_ENDIAN, __LITTLE_ENDIAN).

That way we can better support new architectures w/o hardcoding their
endianness, which is especially useful if they support both.
---
 librhash/byte_order.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/librhash/byte_order.h b/librhash/byte_order.h
index 77b8bb9..5cb081e 100644
--- a/librhash/byte_order.h
+++ b/librhash/byte_order.h
@@ -38,6 +38,8 @@ extern "C" {
 /* detect CPU endianness */
 #if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
 		__BYTE_ORDER == __LITTLE_ENDIAN) || \
+	(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
+		__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
 	defined(CPU_IA32) || defined(CPU_X64) || \
 	defined(__ia64) || defined(__ia64__) || defined(__alpha__) || defined(_M_ALPHA) || \
 	defined(vax) || defined(MIPSEL) || defined(_ARM_) || defined(__arm__)
@@ -46,6 +48,8 @@ extern "C" {
 # define IS_LITTLE_ENDIAN 1
 #elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
 		__BYTE_ORDER == __BIG_ENDIAN) || \
+	(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
+		__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
 	defined(__sparc) || defined(__sparc__) || defined(sparc) || \
 	defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_POWER) || \
 	defined(__POWERPC__) || defined(POWERPC) || defined(__powerpc) || \
-- 
2.8.3