summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/share/endswap.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/share/endswap.h b/include/share/endswap.h
index e71f0f6c..74cdfc3b 100644
--- a/include/share/endswap.h
+++ b/include/share/endswap.h
@@ -33,21 +33,38 @@
#if HAVE_BSWAP32 /* GCC and Clang */
+#define ENDSWAP_16(x) (__builtin_bswap16 (x))
#define ENDSWAP_32(x) (__builtin_bswap32 (x))
#elif defined _MSC_VER /* Windows. Apparently in <stdlib.h>. */
+#define ENDSWAP_16(x) (_byteswap_ushort (x))
#define ENDSWAP_32(x) (_byteswap_ulong (x))
#elif defined HAVE_BYTESWAP_H /* Linux */
#include <byteswap.h>
+#define ENDSWAP_16(x) (bswap_16 (x))
#define ENDSWAP_32(x) (bswap_32 (x))
#else
+#define ENDSWAP_16(x) (((((x) >> 8) & 0xFF00) + ((x) & 0xFF00) << 8))
#define ENDSWAP_32(x) ((((x) >> 24) & 0xFF) + (((x) >> 8) & 0xFF00) + (((x) & 0xFF00) << 8) + (((x) & 0xFF) << 24))
#endif
+
+/* Host to little-endian byte swapping. */
+#if CPU_IS_BIG_ENDIAN
+
+#define H2LE_16(x) ENDSWAP_16 (x)
+#define H2LE_32(x) ENDSWAP_32 (x)
+
+#else
+
+#define H2LE_16(x) (x)
+#define H2LE_32(x) (x)
+
+#endif