summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-08-12 12:04:05 -0700
committerElliott Hughes <enh@google.com>2019-08-12 12:11:42 -0700
commitf86ea02de634b15ffcc1a2b6b991df5f59dba02c (patch)
tree328f8df4dd2864b823420da0c4ba7fecbc170af6
parent5af75ed172e44c781a4feb81a71113612b7f21e6 (diff)
Use as much of the macOS endian support as we can.
Turns out that although there's no <endian.h> or <sys/endian.h>, there are <machine/endian.h> and <sys/_endian.h>, and they're included by other system headers such as <dirent.h>. Reuse the contents of <sys/_endian.h> here for better interop. Bug: http://b/139203733 Test: treehugger Change-Id: Ic0e9bfa1a5b56d05e9e542839d237b6ceae4aa8c
-rw-r--r--base/include/android-base/endian.h25
1 files changed, 15 insertions, 10 deletions
diff --git a/base/include/android-base/endian.h b/base/include/android-base/endian.h
index cbbd8c9bce..10efaa3a81 100644
--- a/base/include/android-base/endian.h
+++ b/base/include/android-base/endian.h
@@ -41,23 +41,28 @@
#else
-/* Mac OS and Windows have nothing. */
-
-#define __LITTLE_ENDIAN 1234
+#if defined(__APPLE__)
+/* macOS has some of the basics. */
+#include <sys/_endian.h>
+#else
+/* Windows really has nothing. */
#define LITTLE_ENDIAN __LITTLE_ENDIAN
-
-#define __BIG_ENDIAN 4321
#define BIG_ENDIAN __BIG_ENDIAN
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
#define BYTE_ORDER __BYTE_ORDER
-
#define htons(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
-#define htonq(x) __builtin_bswap64(x)
-
#define ntohs(x) __builtin_bswap16(x)
#define ntohl(x) __builtin_bswap32(x)
+#endif
+
+/* Neither macOS nor Windows have the rest. */
+
+#define __LITTLE_ENDIAN 1234
+#define __BIG_ENDIAN 4321
+#define __BYTE_ORDER __LITTLE_ENDIAN
+
+#define htonq(x) __builtin_bswap64(x)
+
#define ntohq(x) __builtin_bswap64(x)
#define htobe16(x) __builtin_bswap16(x)