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
From 6ce0f6443a41366dc494f4f34e5b8c4d35a6eba5 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Thu, 29 Nov 2018 13:24:34 -0800
Subject: [PATCH] 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...)
---
 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

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to