From ad9b24b0684d782c629ad1ac2ab37f376f9a8024 Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Wed, 28 Mar 2018 14:06:14 +1100 Subject: [PATCH] util: unbreak endian detection on OpenBSD Since cbee1bfb34274668a05995b9d4c78ddec9e5ea4c endian.h is unconditionally used if available. glibc has byte order defines with two leading underscores. OpenBSD has private defines with a single leading underscore in machine/endian.h and public defines in endian.h with no underscore. The code under the endian.h block did not check if symbols were defined before equating them so '#if __BYTE_ORDER == __LITTLE_ENDIAN' would turn into '#if 0 == 0' which is always true. Fixes: cbee1bfb342 ("meson/configure: detect endian.h instead of trying to guess when it's available") Signed-off-by: Jonathan Gray Reviewed-by: Eric Engestrom Part-of: (cherry picked from commit 7eab6845e9dd49f0ef0bf9a7d986aaf685e77981) --- .pick_status.json | 2 +- src/util/u_endian.h | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 8b0470ca82e..79f97f2fd1b 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1318,7 +1318,7 @@ "description": "util: unbreak endian detection on OpenBSD", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "cbee1bfb34274668a05995b9d4c78ddec9e5ea4c" }, diff --git a/src/util/u_endian.h b/src/util/u_endian.h index 6bbae3c444c..d9ead69a4a4 100644 --- a/src/util/u_endian.h +++ b/src/util/u_endian.h @@ -30,10 +30,19 @@ #ifdef HAVE_ENDIAN_H #include -#if __BYTE_ORDER == __LITTLE_ENDIAN +/* glibc */ +#if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN) # define UTIL_ARCH_LITTLE_ENDIAN 1 # define UTIL_ARCH_BIG_ENDIAN 0 -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN) +# define UTIL_ARCH_LITTLE_ENDIAN 0 +# define UTIL_ARCH_BIG_ENDIAN 1 +#endif + +#if defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN) +# define UTIL_ARCH_LITTLE_ENDIAN 1 +# define UTIL_ARCH_BIG_ENDIAN 0 +#elif defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN) # define UTIL_ARCH_LITTLE_ENDIAN 0 # define UTIL_ARCH_BIG_ENDIAN 1 #endif @@ -60,8 +69,8 @@ # define UTIL_ARCH_BIG_ENDIAN 1 #endif -#elif defined(__OpenBSD__) || defined(__NetBSD__) || \ - defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__NetBSD__) || defined(__FreeBSD__) || \ + defined(__DragonFly__) #include #include