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)
75#endif 75#endif
76} 76}
77 77
78static uint32_t uint24_from_be(char *buff)
79{
80 uint32_t ret = 0;
81 char *tmp = (char*) &ret;
82 memcpy(tmp + 1, buff, 3 * sizeof(char));
83 byte_convert(tmp, sizeof(uint32_t));
84 return ret;
85}
78 86
79#define UINT_TO_HOST(x, n) \ 87#define UINT_TO_HOST(x, n) \
80 (n == 8 ? GUINT64_FROM_BE( *(uint64_t *)(x) ) : \ 88 (n == 8 ? GUINT64_FROM_BE( *(uint64_t *)(x) ) : \
81 (n == 4 ? GUINT32_FROM_BE( *(uint32_t *)(x) ) : \ 89 (n == 4 ? GUINT32_FROM_BE( *(uint32_t *)(x) ) : \
90 (n == 3 ? uint24_from_be( x ) : \
82 (n == 2 ? GUINT16_FROM_BE( *(uint16_t *)(x) ) : \ 91 (n == 2 ? GUINT16_FROM_BE( *(uint16_t *)(x) ) : \
83 *(uint8_t *)(x) ))) 92 *(uint8_t *)(x) ))))
84 93
85#define be64dec(x) GUINT64_FROM_BE( *(uint64_t*)(x) ) 94#define be64dec(x) GUINT64_FROM_BE( *(uint64_t*)(x) )
86 95
87#define get_needed_bytes(x) \ 96#define get_needed_bytes(x) \
88 ( ((uint64_t)x) < (1ULL << 8) ? 1 : \ 97 ( ((uint64_t)x) < (1ULL << 8) ? 1 : \
89 ( ((uint64_t)x) < (1ULL << 16) ? 2 : \ 98 ( ((uint64_t)x) < (1ULL << 16) ? 2 : \
90 ( ((uint64_t)x) < (1ULL << 32) ? 4 : 8))) 99 ( ((uint64_t)x) < (1ULL << 24) ? 3 : \
100 ( ((uint64_t)x) < (1ULL << 32) ? 4 : 8))))
91 101
92#define get_real_bytes(x) (x >> 32 ? 4 : 8) 102#define get_real_bytes(x) (x >> 32 ? 4 : 8)
93 103