aboutsummaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2023-01-11 18:39:02 +0100
committerFelix Fietkau <nbd@nbd.name>2023-10-29 15:56:41 +0100
commit169757c7fd483787fb910c9d7b366fcd91ead49f (patch)
treee1297b5ed7528afa4a62a0ed164493554a5729c2 /tools/include
parentb3d2008f92f15ff776ad6c4f6d113b0cda1bd2d0 (diff)
tools/include: add more endian macros
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/endian.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/include/endian.h b/tools/include/endian.h
index e2ac755667..f625689f3d 100644
--- a/tools/include/endian.h
+++ b/tools/include/endian.h
@@ -37,4 +37,52 @@
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#endif
+#ifndef __linux__
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define htobe16(x) bswap_16(x)
+#define be16toh(x) bswap_16(x)
+#define htobe32(x) bswap_32(x)
+#define be32toh(x) bswap_32(x)
+#define htobe64(x) bswap_64(x)
+#define be64toh(x) bswap_64(x)
+#define htole16(x) (uint16_t)(x)
+#define le16toh(x) (uint16_t)(x)
+#define htole32(x) (uint32_t)(x)
+#define le32toh(x) (uint32_t)(x)
+#define htole64(x) (uint64_t)(x)
+#define le64toh(x) (uint64_t)(x)
+#else
+#define htobe16(x) (uint16_t)(x)
+#define be16toh(x) (uint16_t)(x)
+#define htobe32(x) (uint32_t)(x)
+#define be32toh(x) (uint32_t)(x)
+#define htobe64(x) (uint64_t)(x)
+#define be64toh(x) (uint64_t)(x)
+#define htole16(x) bswap_16(x)
+#define le16toh(x) bswap_16(x)
+#define htole32(x) bswap_32(x)
+#define le32toh(x) bswap_32(x)
+#define htole64(x) bswap_64(x)
+#define le64toh(x) bswap_64(x)
+#endif
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define betoh16(x) bswap_16(x)
+#define betoh32(x) bswap_32(x)
+#define betoh64(x) bswap_64(x)
+#define letoh16(x) (uint16_t)(x)
+#define letoh32(x) (uint32_t)(x)
+#define letoh64(x) (uint64_t)(x)
+#else
+#define betoh16(x) (uint16_t)(x)
+#define betoh32(x) (uint32_t)(x)
+#define betoh64(x) (uint64_t)(x)
+#define letoh16(x) bswap_16(x)
+#define letoh32(x) bswap_32(x)
+#define letoh64(x) bswap_64(x)
+#endif
+#endif
+#endif
+
#endif