[Toybox] [PATCH] macOS: fix endian macros for macOS.

enh enh at google.com
Thu Nov 29 13:26:56 PST 2018


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...)
---
 lib/portability.h | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/lib/portability.h b/lib/portability.h
index e6b542c4..6108474d 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -136,20 +136,28 @@ int utimensat(int fd, const char *path, const
struct timespec times[2], int flag

 // 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
-- 
2.20.0.rc0.387.gc7a69e6b6c-goog
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-macOS-fix-endian-macros-for-macOS.patch
Type: text/x-patch
Size: 1430 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20181129/f697bb56/attachment-0002.bin>


More information about the Toybox mailing list