aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-11-29 13:24:34 -0800
committerRob Landley <rob@landley.net>2018-11-30 11:22:15 -0600
commitb8878682a49fcdd5952a9b8d7fc57eb1508a8adc (patch)
treecb1e295ee2766930b229e6e7b8a8f7c62f6a71d8 /lib
parenta87efd2ab0c9ed622b608ffa93c6ca8526c6474c (diff)
downloadtoybox-b8878682a49fcdd5952a9b8d7fc57eb1508a8adc.tar.gz
macOS: fix endian macros for macOS.
I've also flipped the `#if` because `#ifdef` feels more naturally readable than #ifndef when there's also a `#else`. (I've preserved the oddness of the clearenv declaration being here, because there isn't currently a more suitable `#ifdef __APPLE__` to move it too. Later...)
Diffstat (limited to 'lib')
-rw-r--r--lib/portability.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/portability.h b/lib/portability.h
index 2dba2311..3f841bac 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -98,20 +98,28 @@ char *strcasestr(const char *haystack, const char *needle);
// Work out how to do endianness
-#ifndef __APPLE__
-#include <byteswap.h>
-#include <endian.h>
+#ifdef __APPLE__
-#if __BYTE_ORDER == __BIG_ENDIAN
+#include <libkern/OSByteOrder.h>
+
+#ifdef __BIG_ENDIAN__
#define IS_BIG_ENDIAN 1
#else
#define IS_BIG_ENDIAN 0
#endif
+#define bswap_16(x) OSSwapInt16(x)
+#define bswap_32(x) OSSwapInt32(x)
+#define bswap_64(x) OSSwapInt64(x)
+
int clearenv(void);
+
#else
-#ifdef __BIG_ENDIAN__
+#include <byteswap.h>
+#include <endian.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
#define IS_BIG_ENDIAN 1
#else
#define IS_BIG_ENDIAN 0