diff options
Diffstat (limited to 'src/cn-cbor.c')
-rw-r--r-- | src/cn-cbor.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/cn-cbor.c b/src/cn-cbor.c index 8fadf73..2526b92 100644 --- a/src/cn-cbor.c +++ b/src/cn-cbor.c @@ -49,10 +49,25 @@ static double decode_half(int half) { } #endif /* CBOR_NO_FLOAT */ -/* Fix these if you can't do non-aligned reads */ #define ntoh8p(p) (*(unsigned char*)(p)) + +#ifndef CBOR_ALIGN_READS #define ntoh16p(p) (ntohs(*(unsigned short*)(p))) #define ntoh32p(p) (ntohl(*(uint32_t*)(p))) +#else +static uint16_t ntoh16p(unsigned char *p) { + uint16_t tmp; + memcpy(&tmp, p, sizeof(tmp)); + return ntohs(tmp); +} + +static uint32_t ntoh32p(unsigned char *p) { + uint32_t tmp; + memcpy(&tmp, p, sizeof(tmp)); + return ntohl(tmp); +} +#endif /* CBOR_ALIGN_READS */ + static uint64_t ntoh64p(unsigned char *p) { uint64_t ret = ntoh32p(p); ret <<= 32; |