Commit Diff


commit - ef16f8f6a49e2a26be2782fb00534f8986549987
commit + b3ea1dea0e2d303d837f186e25997987a1854247
blob - 4473cb9179ae177702bf0e89c0be7e18647a51c4
blob + ddc1af872fb085279f8352c9cbc1e0224bac10c7
--- configure.ac
+++ configure.ac
@@ -67,6 +67,16 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 	AC_DEFINE([HAVE_QUEUE_H], 1, [QUEUE_H])
 ], AC_MSG_RESULT(no))
 
+AC_CHECK_HEADER([endian.h], [AC_DEFINE(HAVE_ENDIAN_H, 1, [have endian.h])], [
+	AC_CHECK_HEADER([sys/endian.h],
+		[AC_DEFINE(HAVE_SYS_ENDIAN_H, 1, [have sys/endian.h])], [
+		AC_CHECK_HEADERS([libkern/OSByteOrder.h],
+			[AC_DEFINE(HAVE_LIBKERN_OSBYTEORDER_H, 1, [have OSByteOrder.h])],
+			[AC_MSG_ERROR([can't find compatible endian.h header])],
+			[#include <machine/endian.h>])
+	])
+])
+
 AC_CHECK_DECL(PR_SET_NAME, AC_DEFINE([HAVE_PR_SET_NAME], 1, [pr_set_name]), [],
 	[[#include <sys/prctl.h>]])
 
blob - a0dec05f4f6b7638f3b46d8a5383b1eac83f6621
blob + 2d2216f7e204c10465ec1431d32f3643fe82713d
--- include/compat.h
+++ include/compat.h
@@ -26,6 +26,32 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#if HAVE_ENDIAN_H
+# include <endian.h>
+#elif HAVE_SYS_ENDIAN_H
+# include <sys/endian.h>
+#elif HAVE_LIBKERN_OSBYTEORDER_H
+# include <machine/endian.h>
+# include <libkern/OSByteOrder.h>
+
+# define htobe16(x) OSSwapHostToBigInt16(x)
+# define htole16(x) OSSwapHostToLittleInt16(x)
+# define be16toh(x) OSSwapBigToHostInt16(x)
+# define le16toh(x) OSSwapLittleToHostInt16(x)
+
+# define htobe32(x) OSSwapHostToBigInt32(x)
+# define htole32(x) OSSwapHostToLittleInt32(x)
+# define be32toh(x) OSSwapBigToHostInt32(x)
+# define le32toh(x) OSSwapLittleToHostInt32(x)
+
+# define htobe64(x) OSSwapHostToBigInt64(x)
+# define htole64(x) OSSwapHostToLittleInt64(x)
+# define be64toh(x) OSSwapBigToHostInt64(x)
+# define le64toh(x) OSSwapLittleToHostInt64(x)
+#else
+# error no compatible endian.h header found
+#endif
+
 #if HAVE_EVENT2
 # include <event2/event.h>
 # include <event2/event_compat.h>