From 63a8d2da718c751d8d4134b8cb9a66c80216fbfe Mon Sep 17 00:00:00 2001
From: Alexander von Gluck IV <kallisti5@unixzen.com>
Date: Tue, 3 Aug 2021 13:10:12 -0500
Subject: [PATCH] haiku: patch in our endian code

* There's likely better ways to do this with
  _BSD_SOURCE, but I wasn't able to get the standard
  methods working
---
 lib/isc/include/isc/endian.h | 49 +++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h
index dc770f6..e1a3c50 100644
--- a/lib/isc/include/isc/endian.h
+++ b/lib/isc/include/isc/endian.h
@@ -11,7 +11,54 @@
 
 #pragma once
 
-#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
+#if defined(__HAIKU__)
+
+#include <config/HaikuConfig.h>
+#include <support/ByteOrder.h>
+#include <support/SupportDefs.h>
+
+/*
+ * General byte order swapping functions.
+ */
+#define bswap16(x)  __swap_int16(x)
+#define bswap32(x)  __swap_int32(x)
+#define bswap64(x)  __swap_int64(x)
+
+/*
+ * Host to big endian, host to little endian, big endian to host, and little
+ * endian to host byte order functions as detailed in byteorder(9).
+ */
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define htobe16(x)  bswap16((x))
+#define htobe32(x)  bswap32((x))
+#define htobe64(x)  bswap64((x))
+#define htole16(x)  ((uint16_t)(x))
+#define htole32(x)  ((uint32_t)(x))
+#define htole64(x)  ((uint64_t)(x))
+
+#define be16toh(x)  bswap16((x))
+#define be32toh(x)  bswap32((x))
+#define be64toh(x)  bswap64((x))
+#define le16toh(x)  ((uint16_t)(x))
+#define le32toh(x)  ((uint32_t)(x))
+#define le64toh(x)  ((uint64_t)(x))
+#else /* BYTE_ORDER != LITTLE_ENDIAN */
+#define htobe16(x)  ((uint16_t)(x))
+#define htobe32(x)  ((uint32_t)(x))
+#define htobe64(x)  ((uint64_t)(x))
+#define htole16(x)  bswap16((x))
+#define htole32(x)  bswap32((x))
+#define htole64(x)  bswap64((x))
+
+#define be16toh(x)  ((uint16_t)(x))
+#define be32toh(x)  ((uint32_t)(x))
+#define be64toh(x)  ((uint64_t)(x))
+#define le16toh(x)  bswap16((x))
+#define le32toh(x)  bswap32((x))
+#define le64toh(x)  bswap64((x))
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+
+#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
 	defined(__OpenBSD__) || defined(__bsdi__)
 
 #include <sys/endian.h>
-- 
2.30.2

