MacOS X has a defective sed with no -r.
diff --git a/lib/portability.h b/lib/portability.h
index 9f3f1b7..6ed1dc4 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)