From a716448d1ce282f6c2fce91de5b7385efe330526 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Mon, 9 Feb 2009 21:04:03 +0100 Subject: Add support for 3 bytes offsets. --- src/bplist.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bplist.c b/src/bplist.c index fb24a1e..cc3223f 100644 --- a/src/bplist.c +++ b/src/bplist.c @@ -75,19 +75,29 @@ static void byte_convert(uint8_t * address, size_t size) #endif } +static uint32_t uint24_from_be(char *buff) +{ + uint32_t ret = 0; + char *tmp = (char*) &ret; + memcpy(tmp + 1, buff, 3 * sizeof(char)); + byte_convert(tmp, sizeof(uint32_t)); + return ret; +} #define UINT_TO_HOST(x, n) \ (n == 8 ? GUINT64_FROM_BE( *(uint64_t *)(x) ) : \ (n == 4 ? GUINT32_FROM_BE( *(uint32_t *)(x) ) : \ + (n == 3 ? uint24_from_be( x ) : \ (n == 2 ? GUINT16_FROM_BE( *(uint16_t *)(x) ) : \ - *(uint8_t *)(x) ))) + *(uint8_t *)(x) )))) #define be64dec(x) GUINT64_FROM_BE( *(uint64_t*)(x) ) #define get_needed_bytes(x) \ ( ((uint64_t)x) < (1ULL << 8) ? 1 : \ ( ((uint64_t)x) < (1ULL << 16) ? 2 : \ - ( ((uint64_t)x) < (1ULL << 32) ? 4 : 8))) + ( ((uint64_t)x) < (1ULL << 24) ? 3 : \ + ( ((uint64_t)x) < (1ULL << 32) ? 4 : 8)))) #define get_real_bytes(x) (x >> 32 ? 4 : 8) -- cgit v1.1-32-gdbae