commit - 291ecc472387b3e2c14aeb08563387771faa5192
commit + 1066c216d10ab00c41500809f448f0ba90ae060d
blob - /dev/null
blob + 2eb594e582e7573a0e5e2151b49beccff4cbc5bf (mode 644)
--- /dev/null
+++ compat/endian/endian.h
+#include "../../config.h"
+
+#if HAVE_SYS_ENDIAN
+# include <sys/endian.h>
+#elif HAVE_MACHINE_ENDIAN
+# 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
+
blob - 0568beae3e3931cda725af7b2d2299fc9626ee22
blob + 053c66ff95af1c3ffa35f541c552c619095dbfcf
--- configure
+++ configure
HAVE_ACCEPT4=
HAVE_ASR_RUN=
HAVE_BUFFEREVENT_READ_PRESSURE_CB=
+HAVE_ENDIAN=0
HAVE_ERR=
HAVE_EVENT_ASR_RUN=
HAVE_FREEZERO=
HAVE_IMSG=
HAVE_LIBEVENT=
HAVE_LIBEVENT2=
+HAVE_MACHINE_ENDIAN=0
HAVE_PLEDGE=
HAVE_REALLOCARRAY=
HAVE_RECALLOCARRAY=
HAVE_STRLCAT=
HAVE_STRLCPY=
HAVE_STRTONUM=
+HAVE_SYS_ENDIAN=0
HAVE_SYS_QUEUE=
HAVE_SYS_TREE=
HAVE_UNVEIL=
if ! singletest WAIT_ANY WAIT_ANY; then
CFLAGS="${CFLAGS} -DWAIT_ANY=-1"
+fi
+
+runtest endian ENDIAN || \
+runtest machine_endian MACHINE_ENDIAN || \
+runtest sys_endian SYS_ENDIAN || true
+
+if [ "${HAVE_ENDIAN}" -eq 0 -a \
+ "${HAVE_SYS_ENDIAN}" -eq 0 -a \
+ "${HAVE_MACHINE_ENDIAN}" -eq 0 ]; then
+ echo "FATAL: no endian header found" 1>&2
+ echo "FATAL: no endian header found" 1>&3
+ exit 1
fi
runtest accept4 ACCEPT4 -D_GNU_SOURCE || true
# things we can provide by ourselves:
+if [ "${HAVE_ENDIAN}" -eq 0 ]; then
+ CFLAGS="-I compat/endian ${CFLAGS}"
+fi
+
if [ "${HAVE_IMSG}" -eq 0 ]; then
CFLAGS="-I compat/imsg ${CFLAGS}"
COMPATS="compat/imsg/imsg.c compat/imsg/imsg-buffer.c ${COMPATS}"
#define HAVE_ACCEPT4 ${HAVE_ACCEPT4}
#define HAVE_ASR_RUN ${HAVE_ASR_RUN}
#define HAVE_BUFFEREVENT_READ_PRESSURE_CB ${HAVE_BUFFEREVENT_READ_PRESSURE_CB}
+#define HAVE_ENDIAN ${HAVE_ENDIAN}
#define HAVE_ERR ${HAVE_ERR}
#define HAVE_EVENT_ASR_RUN ${HAVE_EVENT_ASR_RUN}
#define HAVE_FREEZERO ${HAVE_FREEZERO}
#define HAVE_IMSG ${HAVE_IMSG}
#define HAVE_LIBEVENT ${HAVE_LIBEVENT}
#define HAVE_LIBEVENT2 ${HAVE_LIBEVENT2}
+#define HAVE_MACHINE_ENDIAN ${HAVE_MACHINE_ENDIAN}
#define HAVE_PLEDGE ${HAVE_PLEDGE}
#define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
#define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
#define HAVE_STRLCAT ${HAVE_STRLCAT}
#define HAVE_STRLCPY ${HAVE_STRLCPY}
#define HAVE_STRTONUM ${HAVE_STRTONUM}
+#define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
#define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
#define HAVE_SYS_TREE ${HAVE_SYS_TREE}
#define HAVE_UNVEIL ${HAVE_UNVEIL}
blob - /dev/null
blob + 3bbff60d30f536b3269a7aa65bf0283efb89196a (mode 644)
--- /dev/null
+++ tests/endian.c
+/*
+ * Copyright (c) 2023 Omar Polo <op@omarpolo.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <endian.h>
+#include <stdint.h>
+
+int
+main(void)
+{
+ uint16_t x;
+
+ x = 42;
+ return (htobe16(x));
+}
blob - /dev/null
blob + 2413b5896b13f658f73c6c73ab5100e41ec5e769 (mode 644)
--- /dev/null
+++ tests/machine_endian.c
+/*
+ * Copyright (c) 2023 Omar Polo <op@omarpolo.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <machine/endian.h>
+#include <libkern/OSByteOrder.h>
+#include <stdint.h>
+
+int
+main(void)
+{
+ uint16_t x;
+
+ x = 42;
+ return (OSSwapHostToBigInt16(x));
+}
blob - /dev/null
blob + bba56c9ed2ea334c99fe1d986c895aae65f18011 (mode 644)
--- /dev/null
+++ tests/sys_endian.c
+/*
+ * Copyright (c) 2023 Omar Polo <op@omarpolo.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/endian.h>
+#include <stdint.h>
+
+int
+main(void)
+{
+ uint16_t x;
+
+ x = 42;
+ return (htobe16(x));
+}