aboutsummaryrefslogtreecommitdiffstats
path: root/byteorder.h
diff options
context:
space:
mode:
Diffstat (limited to 'byteorder.h')
-rw-r--r--byteorder.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/byteorder.h b/byteorder.h
new file mode 100644
index 0000000..436c320
--- /dev/null
+++ b/byteorder.h
@@ -0,0 +1,49 @@
+
+#if sun
+
+#define LITTLE_ENDIAN 1234
+#define BIG_ENDIAN 4321
+#define PDP_ENDIAN 3412
+
+#include <sys/isa_defs.h>
+
+#if defined(_LITTLE_ENDIAN)
+#define BYTE_ORDER LITTLE_ENDIAN
+#elif defined(_BIG_ENDIAN)
+#define BYTE_ORDER BIG_ENDIAN
+#endif
+
+#else
+
+/* linux */
+#include <endian.h>
+
+#endif
+
+
+/* ---------------------------------------------------------------------- */
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+
+# define cpu_to_le32(x) (x)
+# define cpu_to_le16(x) (x)
+# define le32_to_cpu(x) (x)
+# define le16_to_cpu(x) (x)
+
+#elif BYTE_ORDER == BIG_ENDIAN
+
+# define cpu_to_le32(x) (\
+ ((x & 0x000000FF) << 24) | \
+ ((x & 0x0000FF00) << 8) | \
+ ((x & 0x00FF0000) >> 8) | \
+ ((x & 0xFF000000) >> 24))
+# define le32_to_cpu(x) cpu_to_le32(x)
+
+# define cpu_to_le16(x) (((x & 0x00FF) << 8) | (x >> 8))
+# define le16_to_cpu(x) cpu_to_le16(x)
+
+#else
+
+# error Unknow byte order type
+
+#endif