From 815f4148b2eff6c64c764e910e79677d5a67adc7 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Fri, 16 Dec 2016 16:52:35 +0900 Subject: Uses built-in byte swap if available (Apple) and if bswap_XX is undefined. Defers to pre-defined version if found (e.g. protobuf). For protobuf case, the definitions are identical and thus include order should not affect results. --- src/compat/byteswap.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/compat') diff --git a/src/compat/byteswap.h b/src/compat/byteswap.h index 07ca535728..56f4240e49 100644 --- a/src/compat/byteswap.h +++ b/src/compat/byteswap.h @@ -15,6 +15,23 @@ #include #endif +#if defined(__APPLE__) + +#if !defined(bswap_16) + +// Mac OS X / Darwin features; we include a check for bswap_16 because if it is already defined, protobuf has +// defined these macros for us already; if it isn't, we do it ourselves. In either case, we get the exact same +// result regardless which path was taken +#include +#define bswap_16(x) OSSwapInt16(x) +#define bswap_32(x) OSSwapInt32(x) +#define bswap_64(x) OSSwapInt64(x) + +#endif // !defined(bswap_16) + +#else +// Non-Mac OS X / non-Darwin + #if HAVE_DECL_BSWAP_16 == 0 inline uint16_t bswap_16(uint16_t x) { @@ -44,4 +61,6 @@ inline uint64_t bswap_64(uint64_t x) } #endif // HAVE_DECL_BSWAP64 +#endif // defined(__APPLE__) + #endif // BITCOIN_COMPAT_BYTESWAP_H -- cgit v1.2.3