summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-02-09 21:04:03 +0100
committerGravatar Jonathan Beck2009-02-09 21:04:03 +0100
commita716448d1ce282f6c2fce91de5b7385efe330526 (patch)
treeab577364330822b0fab918191521adf3338027e1
parent4278fced578920c4b9c1ffe0862e94d90430b227 (diff)
downloadlibplist-a716448d1ce282f6c2fce91de5b7385efe330526.tar.gz
libplist-a716448d1ce282f6c2fce91de5b7385efe330526.tar.bz2
Add support for 3 bytes offsets.
-rw-r--r--src/bplist.c14
1 files 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)