From a1dbe722fa9f92bc61f27edce133ea209c9b5d49 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 28 Apr 2014 17:25:27 +0000 Subject: [PATCH] private: Unpack utility functions (upk_u{16,32,64}le) --- private.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/private.h b/private.h index f149223..fcbf02b 100644 --- a/private.h +++ b/private.h @@ -30,4 +30,36 @@ int blkmk_flsl(unsigned long n) return i; } +static inline +uint16_t upk_u16le(const void * const bufp, const int offset) +{ + const uint8_t * const buf = bufp; + return (((uint16_t)buf[offset+0]) << 0) + | (((uint16_t)buf[offset+1]) << 8); +} + +static inline +uint32_t upk_u32le(const void * const bufp, const int offset) +{ + const uint8_t * const buf = bufp; + return (((uint32_t)buf[offset+0]) << 0) + | (((uint32_t)buf[offset+1]) << 8) + | (((uint32_t)buf[offset+2]) << 0x10) + | (((uint32_t)buf[offset+3]) << 0x18); +} + +static inline +uint64_t upk_u64le(const void * const bufp, const int offset) +{ + const uint8_t * const buf = bufp; + return (((uint64_t)buf[offset+0]) << 0) + | (((uint64_t)buf[offset+1]) << 8) + | (((uint64_t)buf[offset+2]) << 0x10) + | (((uint64_t)buf[offset+3]) << 0x18) + | (((uint64_t)buf[offset+4]) << 0x20) + | (((uint64_t)buf[offset+5]) << 0x28) + | (((uint64_t)buf[offset+6]) << 0x30) + | (((uint64_t)buf[offset+7]) << 0x38); +} + #endif