Commit Diff


commit - 23a9967121cd2e7ead33dc7ccdeac7d8be2855c8
commit + 4c1ef99ca3a41b189f7f1ce8366e84328835e152
blob - a994af5c7645accbb068605407520b0175a008ad
blob + ad1273c0a22318d0fc4e2061e5313da3d9857ee7
--- Makefile
+++ Makefile
@@ -34,6 +34,7 @@ DISTFILES =	CHANGES \
 		amused.1 \
 		configure \
 		configure.local.example \
+		endian.h \
 		imsg.h \
 		queue.h \
 		tests.c \
blob - 478ac4b58ff524c05d96c620edcf889183dd58e7
blob + ab6762a5faffa05b3485da9b150499246a59840d
--- configure
+++ configure
@@ -209,6 +209,7 @@ command -v pkg-config 2>/dev/null 1>&2 && {
 #----------------------------------------------------------------------
 
 HAVE_CAPSICUM=
+HAVE_ENDIAN_H=
 HAVE_ERR=
 HAVE_EXPLICIT_BZERO=
 HAVE_FLOCK=
@@ -246,6 +247,7 @@ HAVE_STRLCPY=
 HAVE_STRNDUP=
 HAVE_STRNLEN=
 HAVE_STRTONUM=
+HAVE_SYS_ENDIAN_H=
 HAVE_SYS_FILE=
 HAVE_SYS_QUEUE=
 HAVE_SYSTRACE=0
@@ -537,6 +539,7 @@ if runtest -MMD _MMD -MMD; then
 fi
 
 runtest capsicum	CAPSICUM			  || true
+runtest endian_h	ENDIAN_H			  || true
 runtest err		ERR				  || true
 runtest explicit_bzero	EXPLICIT_BZERO			  || true
 runtest flock		FLOCK				  || true
@@ -576,6 +579,7 @@ runtest strndup		STRNDUP				  || true
 runtest strnlen		STRNLEN				  || true
 runtest strtonum	STRTONUM			  || true
 runtest sys_queue	SYS_QUEUE			  || true
+runtest sys_endian_h	SYS_ENDIAN_H			  || true
 runtest sys_file	SYS_FILE			  || true
 runtest timespecsub	TIMESPECSUB			  || true
 runtest unveil		UNVEIL				  || true
@@ -758,6 +762,7 @@ cat << __HEREDOC__
  * Results of configuration feature-testing.
  */
 #define HAVE_CAPSICUM ${HAVE_CAPSICUM}
+#define HAVE_ENDIAN_H ${HAVE_ENDIAN_H}
 #define HAVE_ERR ${HAVE_ERR}
 #define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
 #define HAVE_FLOCK ${HAVE_FLOCK}
@@ -787,6 +792,7 @@ cat << __HEREDOC__
 #define HAVE_STRNDUP ${HAVE_STRNDUP}
 #define HAVE_STRNLEN ${HAVE_STRNLEN}
 #define HAVE_STRTONUM ${HAVE_STRTONUM}
+#define HAVE_SYS_ENDIAN_H ${HAVE_SYS_ENDIAN_H}
 #define HAVE_SYS_FILE ${HAVE_SYS_FILE}
 #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
 #define HAVE_SYSTRACE ${HAVE_SYSTRACE}
blob - /dev/null
blob + ca4997d23e9ca92fd81697865e695f81039f7af3 (mode 644)
--- /dev/null
+++ endian.h
@@ -0,0 +1,23 @@
+#include "../../config.h"
+
+#if HAVE_SYS_ENDIAN_H
+# include <sys/endian.h>
+#else
+# 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)
+#endif