summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/endianness.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/endianness.h b/src/endianness.h
index ee9a1a5..972e51b 100644
--- a/src/endianness.h
+++ b/src/endianness.h
@@ -19,6 +19,13 @@
#endif
#endif
+#ifndef __BYTE_ORDER
+#ifndef _WIN32
+#warning __BYTE_ORDER is not defined, assuming little endian
+#endif
+#define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
#ifndef be16toh
#if __BYTE_ORDER == __BIG_ENDIAN
#define be16toh(x) (x)
@@ -27,6 +34,10 @@
#endif
#endif
+#ifndef htobe16
+#define htobe16 be16toh
+#endif
+
#ifndef le16toh
#if __BYTE_ORDER == __BIG_ENDIAN
#define le16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
@@ -35,6 +46,9 @@
#endif
#endif
+#ifndef htole16
+#define htole16 le16toh
+#endif
#ifndef __bswap_32
#define __bswap_32(x) ((((x) & 0xFF000000) >> 24) \
@@ -102,4 +116,15 @@
#define htole64 le64toh
#endif
+#if (defined(__BIG_ENDIAN__) \
+ && !defined(__FLOAT_WORD_ORDER__)) \
+ || (defined(__FLOAT_WORD_ORDER__) \
+ && __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define float_bswap64(x) __bswap_64(x)
+#define float_bswap32(x) __bswap_32(x)
+#else
+#define float_bswap64(x) (x)
+#define float_bswap32(x) (x)
+#endif
+
#endif /* ENDIANNESS_H */