summaryrefslogtreecommitdiff
path: root/include/endian.h
diff options
context:
space:
mode:
authorVladimir Zapolskiy <vzapolskiy@gmail.com>2010-06-01 23:22:57 +0400
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2010-07-27 13:21:16 +0200
commitc6d6237819037168a6923ac080e348e54615422c (patch)
tree4ced38850f566f69504c4ea8ee7cb58180294a60 /include/endian.h
parent85b7ea33088fa16d319adbd228fc152f5b9da730 (diff)
endian.h: add BSD convertions between big/little-endian byte order
This patch adds support for convertion of values between host and big-/little-endian byte order. Signed-off-by: Vladimir Zapolskiy <vzapolskiy@gmail.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'include/endian.h')
-rw-r--r--include/endian.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/endian.h b/include/endian.h
index 2f7bce100..0ba738463 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -55,4 +55,42 @@
# define __LONG_LONG_PAIR(HI, LO) HI, LO
#endif
+
+#ifdef __USE_BSD
+/* Conversion interfaces. */
+# include <byteswap.h>
+
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+# define htobe16(x) __bswap_16 (x)
+# define htole16(x) (x)
+# define be16toh(x) __bswap_16 (x)
+# define le16toh(x) (x)
+
+# define htobe32(x) __bswap_32 (x)
+# define htole32(x) (x)
+# define be32toh(x) __bswap_32 (x)
+# define le32toh(x) (x)
+
+# define htobe64(x) __bswap_64 (x)
+# define htole64(x) (x)
+# define be64toh(x) __bswap_64 (x)
+# define le64toh(x) (x)
+# else
+# define htobe16(x) (x)
+# define htole16(x) __bswap_16 (x)
+# define be16toh(x) (x)
+# define le16toh(x) __bswap_16 (x)
+
+# define htobe32(x) (x)
+# define htole32(x) __bswap_32 (x)
+# define be32toh(x) (x)
+# define le32toh(x) __bswap_32 (x)
+
+# define htobe64(x) (x)
+# define htole64(x) __bswap_64 (x)
+# define be64toh(x) (x)
+# define le64toh(x) __bswap_64 (x)
+# endif
+#endif
+
#endif /* endian.h */