summaryrefslogtreecommitdiffhomepage
path: root/src/internal/perk_reader_impl.h
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-12-03 23:20:19 -0500
committermidipix <writeonce@midipix.org>2016-11-10 23:35:30 -0500
commit413f560bf6f6c38fe141e3cab3c81996db83045b (patch)
tree8d2b5b85017f4afcb6a8384e2653de998891de96 /src/internal/perk_reader_impl.h
parent06305207b9a310dcee901d434328aa8e77f8d656 (diff)
downloadperk-413f560bf6f6c38fe141e3cab3c81996db83045b.tar.bz2
perk-413f560bf6f6c38fe141e3cab3c81996db83045b.tar.xz
internal headers: rename perk_impl.h to perk_reader_impl.h
Diffstat (limited to 'src/internal/perk_reader_impl.h')
-rw-r--r--src/internal/perk_reader_impl.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/internal/perk_reader_impl.h b/src/internal/perk_reader_impl.h
new file mode 100644
index 0000000..bda7581
--- /dev/null
+++ b/src/internal/perk_reader_impl.h
@@ -0,0 +1,50 @@
+#ifndef PERK_IMPL_H
+#define PERK_IMPL_H
+
+#include <stdint.h>
+#include <endian.h>
+
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+
+static inline uint16_t pe_read_short(const unsigned char * raw)
+{
+ return *(uint16_t *)raw;
+}
+
+static inline uint32_t pe_read_long(const unsigned char * raw)
+{
+ return *(uint32_t *)raw;
+}
+
+static inline uint64_t pe_read_quad(const unsigned char * raw)
+{
+ return *(uint64_t *)raw;
+}
+
+#else
+
+static inline uint16_t pe_read_short(const unsigned char * raw)
+{
+ uint16_t x = *(uint16_t *)raw;
+ return x<<8 | x>>8;
+}
+
+static inline uint32_t pe_swap_long(uint32_t x)
+{
+ return x<<24 | (x<<8) & 0xff0000 | (x>>8) & 0xff00 | x>>24;
+}
+
+static inline uint32_t pe_read_long(const unsigned char * raw)
+{
+ return pe_swap_long(*(uint32_t *)raw);
+}
+
+static inline uint64_t pe_read_quad(const unsigned char * raw)
+{
+ uint64_t x = *(uint64_t *)raw;
+ return ((uint64_t)pe_swap_long(x)<<32) | pe_swap_long(x>>32);
+}
+
+#endif
+
+#endif