aboutsummaryrefslogtreecommitdiff
path: root/endian.h
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-11-18 13:43:28 +1300
committerDavid Phillips <david@sighup.nz>2017-11-18 13:43:28 +1300
commit51407f1797c77c742815d3135632666f4d940cb7 (patch)
tree9eae513f96a9fdcb9a6a9b17d804a3a63b949308 /endian.h
parent8816f394206b7642c159caf0d2db9b3ab55b7d10 (diff)
downloadsand-leek-51407f1797c77c742815d3135632666f4d940cb7.tar.xz
Switch to in-house byte-order switching
Diffstat (limited to 'endian.h')
-rw-r--r--endian.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/endian.h b/endian.h
new file mode 100644
index 0000000..6ebda83
--- /dev/null
+++ b/endian.h
@@ -0,0 +1,13 @@
+#ifndef SAND_LEEK_ENDIAN_H
+#define SAND_LEEK_ENDIAN_H
+
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# define sl_htobe32(x) (x)
+#else
+# define sl_htobe32(x) (((x & 0x000000FF) << 24) | \
+ ((x & 0xFF000000) >> 24)) | \
+ ((x & 0x0000FF00) << 8) | \
+ ((x & 0x00FF0000) >> 8)
+#endif
+
+#endif /* ifndef SAND_LEEK_ENDIAN_H */