aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/endian_tools.h
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2020-01-01 16:01:42 -0500
committerDaniil Cherednik <dan.cherednik@gmail.com>2020-01-01 16:01:42 -0500
commit6b9d92b3797207551547a7a95a0ba28642bf4dd0 (patch)
treedc42443b4d30c2914361c4f436f2a1f42e571185 /src/lib/endian_tools.h
parent3d69df17657c40030fb486a86ef179a42b3873ca (diff)
downloadatracdenc-6b9d92b3797207551547a7a95a0ba28642bf4dd0.tar.gz
Fix compilation on POSIX platforms.0.0.2
Diffstat (limited to 'src/lib/endian_tools.h')
-rw-r--r--src/lib/endian_tools.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/endian_tools.h b/src/lib/endian_tools.h
new file mode 100644
index 0000000..519cca1
--- /dev/null
+++ b/src/lib/endian_tools.h
@@ -0,0 +1,60 @@
+/*
+ * This file is part of AtracDEnc.
+ *
+ * AtracDEnc is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * AtracDEnc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with AtracDEnc; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LIB_ENDIAN_H
+#define LIB_ENDIAN_H
+
+#include <stdint.h>
+
+static inline uint32_t swapbyte32_on_le(uint32_t in) {
+#ifdef BIGENDIAN_ORDER
+ return in;
+#else
+ return ((in & 0xff) << 24) | ((in & 0xff00) << 8) | ((in & 0xff0000) >> 8) | ((in & 0xff000000) >> 24);
+#endif
+}
+
+static inline uint16_t swapbyte16_on_le(uint16_t in) {
+#ifdef BIGENDIAN_ORDER
+ return in;
+#else
+ return ((in & 0xff) << 8) | ((in & 0xff00) >> 8);
+#endif
+}
+
+#ifdef __cplusplus
+
+static inline int16_t conv_ntoh(int16_t in) {
+ return (int16_t)swapbyte16_on_le((uint16_t)in);
+}
+
+static inline uint16_t conv_ntoh(uint16_t in) {
+ return swapbyte16_on_le(in);
+}
+
+static inline int32_t conv_ntoh(int32_t in) {
+ return (int32_t)swapbyte32_on_le((uint32_t)in);
+}
+
+static inline uint32_t conv_ntoh(uint32_t in) {
+ return swapbyte32_on_le(in);
+}
+
+#endif
+
+#endif \ No newline at end of file