aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/portability.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/portability.h b/lib/portability.h
index 9f3f1b78..6ed1dc4f 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -1,13 +1,30 @@
-
// Humor glibc to get dprintf, then #define it to something more portable.
#define _GNU_SOURCE
#include <stdio.h>
#define fdprintf(...) dprintf(__VA_ARGS__)
+
+#ifndef __APPLE__
+#include <byteswap.h>
#include <endian.h>
#if __BYTE_ORDER == __BIG_ENDIAN
#define IS_BIG_ENDIAN 1
+#else
+#define IS_BIG_ENDIAN 0
+#endif
+
+#else
+
+#ifdef __BIG_ENDIAN__
+#define IS_BIG_ENDIAN 1
+#else
+#define IS_BIG_ENDIAN 0
+#endif
+
+#endif
+
+#if IS_BIG_ENDIAN
#define IS_LITTLE_ENDIAN 0
#define SWAP_BE16(x) (x)
#define SWAP_BE32(x) (x)
@@ -17,7 +34,6 @@
#define SWAP_LE64(x) bswap_64(x)
#else
#define IS_LITTLE_ENDIAN 1
-#define IS_BIG_ENDIAN 0
#define SWAP_BE16(x) bswap_16(x)
#define SWAP_BE32(x) bswap_32(x)
#define SWAP_BE64(x) bswap_64(x)