Skip to content

Instantly share code, notes, and snippets.

@shulima
Created March 25, 2015 22:29
Show Gist options
  • Save shulima/5ad4c6fbfdfd27048fe8 to your computer and use it in GitHub Desktop.
Save shulima/5ad4c6fbfdfd27048fe8 to your computer and use it in GitHub Desktop.
Add MacOSX-specific byteswap defines
diff --git a/src/inspect-apps.c b/src/inspect-apps.c
index 836a160..8bf7073 100644
--- a/src/inspect-apps.c
+++ b/src/inspect-apps.c
@@ -35,11 +35,22 @@
#include <sys/endian.h>
#endif
-/* be32toh is usually a macro definend in <endian.h>, but it might be
+/* be32toh is usually a macro defined in <endian.h>, but it might be
* a function in some system so check both, and if neither is defined
* then define be32toh for RHEL 5.
*/
#if !defined(HAVE_BE32TOH) && !defined(be32toh)
+
+#if defined __APPLE__ && defined __MACH__
+/* Define/include necessary items on MacOS X */
+#include <machine/endian.h>
+#define __BIG_ENDIAN BIG_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#define __BYTE_ORDER BYTE_ORDER
+#include <libkern/OSByteOrder.h>
+#define __bswap_32 OSSwapConstInt32
+#endif /* __APPLE__ */
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define be32toh(x) __bswap_32 (x)
#else
diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index 619706c..634b8e4 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -36,6 +36,12 @@
#include <sys/endian.h>
#endif
+#if defined __APPLE__ && defined __MACH__
+#include <libkern/OSByteOrder.h>
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
+#endif
+
#include <pcre.h>
#include "c-ctype.h"
diff --git a/src/journal.c b/src/journal.c
index 1070067..c563b7f 100644
--- a/src/journal.c
+++ b/src/journal.c
@@ -35,6 +35,11 @@
#include <sys/endian.h>
#endif
+#if defined __APPLE__ && defined __MACH__
+#include <libkern/OSByteOrder.h>
+#define be64toh(x) OSSwapBigToHostInt64(x)
+#endif
+
#include "full-read.h"
#include "guestfs.h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment