Hi Jessica,
Am 09.09.2017 9:41 nachm. schrieb <jessica.l.hamilton@xxxxxxxxx>:
Revision: hrev51407
Commit: b8cfd96db10fc4341ffd3b552d28d95f716e895e
URL: http://cgit.haiku-os.org/haiku/commit/?id=b8cfd96db10f
Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx>
Date: Sat Sep 9 19:37:32 2017 UTC
endian.h: add BSD extensions when _BSD_SOURCE is defined.
----------------------------------------------------------------------------
diff --git a/headers/posix/endian.h b/headers/posix/endian.h
index ba93bb1..02b5c32 100644
--- a/headers/posix/endian.h
+++ b/headers/posix/endian.h
@@ -7,7 +7,9 @@
#include <config/HaikuConfig.h>
-
+#ifdef _BSD_SOURCE
+#include <support/ByteOrder.h>
+#endif
/* Defines architecture dependent endian constants.
* The constant reflects the byte order, "4" is the most
@@ -28,4 +30,49 @@
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#define __BYTE_ORDER BYTE_ORDER
+#ifdef _BSD_SOURCE
+
+/*
+ * 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 */
+
+#endif /* _BSD_SOURCE */
+
#endif /* _ENDIAN_H_ */
As I see it, this kind of compatibility is usually added in
headers/compatibility/bsd.
Bye
Jérome