aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChristian Andersen <csandersen3@gmail.com>2024-02-04 19:16:14 +0100
committerBrent Cook <busterb@gmail.com>2024-03-03 15:32:50 -0600
commit168f4bc61b024bb09c40440ad4d795ad31f2f148 (patch)
treeec112a8fa201fc1fc84b42229b82ea715981ab25 /include
parentd06a11360d1a7632c4629ddf29093000b2397645 (diff)
downloadportable-168f4bc61b024bb09c40440ad4d795ad31f2f148.tar.gz
portable-168f4bc61b024bb09c40440ad4d795ad31f2f148.tar.bz2
portable-168f4bc61b024bb09c40440ad4d795ad31f2f148.zip
Windows: Improve the check for endianness when using Visual Studio.
Visual studio does not define __BYTE_ORDER__ so all architectures were detected as LITTLE_ENDIAN since both __BYTE_ORDER__ and __ORDER_LITTLE_ENDIAN__ would evaluate to 0 and compare equal. This updates the checks to use CMakes detection of endianness, with a hard error, if this also fails.
Diffstat (limited to 'include')
-rw-r--r--include/compat/endian.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/include/compat/endian.h b/include/compat/endian.h
index d0dcfe3..5376c1a 100644
--- a/include/compat/endian.h
+++ b/include/compat/endian.h
@@ -13,13 +13,28 @@
13#define PDP_ENDIAN 3412 13#define PDP_ENDIAN 3412
14 14
15/* 15/*
16 * Use GCC and Visual Studio compiler defines to determine endian. 16 * Use GCC compiler defines to determine endianness.
17 */ 17 */
18#if defined(__BYTE_ORDER__)
18#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 19#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
19#define BYTE_ORDER LITTLE_ENDIAN 20#define BYTE_ORDER LITTLE_ENDIAN
20#else 21#else
21#define BYTE_ORDER BIG_ENDIAN 22#define BYTE_ORDER BIG_ENDIAN
22#endif 23#endif
24#endif
25
26/*
27 * Use build system defines to determine endianness.
28 */
29#if !defined(BYTE_ORDER)
30#if defined(HAVE_LITTLE_ENDIAN)
31#define BYTE_ORDER LITTLE_ENDIAN
32#elif defined(HAVE_BIG_ENDIAN)
33#define BYTE_ORDER BIG_ENDIAN
34#else
35#error "Could not detect endianness."
36#endif
37#endif
23 38
24#elif defined(HAVE_ENDIAN_H) 39#elif defined(HAVE_ENDIAN_H)
25#include_next <endian.h> 40#include_next <endian.h>