From 36f5f7918f28b7c2877a8bef373096ea39d905ad Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 25 Jan 2025 14:16:47 +0100 Subject: [PATCH] fix(endian): rely on system headers where possible Problem: Macros (re)defined in `endian.h` conflict with system headers on FreeBSD (at least). Solution: Rely on system `endian.h` on OpenBSD, FreeBSD, NetBSD, and DragonFly Ref. https://github.com/mikepb/endian.h/issues/4 --- lib/src/portable/endian.h | 45 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/lib/src/portable/endian.h b/lib/src/portable/endian.h index bd6f2370..6aa4438d 100644 --- a/lib/src/portable/endian.h +++ b/lib/src/portable/endian.h @@ -4,8 +4,10 @@ // be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it // an example on how to get the endian conversion functions on different platforms. -#ifndef PORTABLE_ENDIAN_H__ -#define PORTABLE_ENDIAN_H__ +// updates from https://github.com/mikepb/endian.h/issues/4 + +#ifndef ENDIAN_H +#define ENDIAN_H #if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) @@ -13,9 +15,22 @@ #endif -#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || defined(__EMSCRIPTEN__) +#if defined(HAVE_ENDIAN_H) || \ + defined(__linux__) || \ + defined(__GNU__) || \ + defined(__OpenBSD__) || \ + defined(__CYGWIN__) || \ + defined(__MSYS__) || \ + defined(__EMSCRIPTEN__) -# include +# include + +#elif defined(HAVE_SYS_ENDIAN_H) || \ + defined(__FreeBSD__) || \ + defined(__NetBSD__) || \ + defined(__DragonFly__) + +# include #elif defined(__APPLE__) # define __BYTE_ORDER BYTE_ORDER @@ -75,31 +90,9 @@ # error byte order not supported # endif # endif -#elif defined(__OpenBSD__) - -# include - -# define __BYTE_ORDER BYTE_ORDER -# define __BIG_ENDIAN BIG_ENDIAN -# define __LITTLE_ENDIAN LITTLE_ENDIAN -# define __PDP_ENDIAN PDP_ENDIAN - -#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) - -# include - -# define be16toh(x) betoh16(x) -# define le16toh(x) letoh16(x) - -# define be32toh(x) betoh32(x) -# define le32toh(x) letoh32(x) - -# define be64toh(x) betoh64(x) -# define le64toh(x) letoh64(x) #elif defined(__WINDOWS__) - # if defined(_MSC_VER) && !defined(__clang__) # include # define B_SWAP_16(x) _byteswap_ushort(x)