diff options
Diffstat (limited to 'src/common')
-rwxr-xr-x | src/common/endianness.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/common/endianness.c b/src/common/endianness.c index 17ee252..059295d 100755 --- a/src/common/endianness.c +++ b/src/common/endianness.c @@ -133,20 +133,37 @@ bool read_u32(uint32_t *target, const bin_t *data, off_t *pos, off_t len, Source switch (endian) { + case SRE_LITTLE: +#if __BYTE_ORDER == __LITTLE_ENDIAN + + *target = data[*pos] | (uint32_t)data[*pos + 1] << 8; + *target |= data[*pos + 2] << 16 | (uint32_t)data[*pos + 3] << 24; + +#elif __BYTE_ORDER == __BIG_ENDIAN + *target = data[*pos + 3] | (uint32_t)data[*pos + 2] << 8; + *target |= data[*pos + 1] << 16 | (uint32_t)data[*pos] << 24; + +#else + +# error "TODO : PDP !" + +#endif + + break; case SRE_BIG: #if __BYTE_ORDER == __LITTLE_ENDIAN - *target = data[*pos + 3] | (uint16_t)data[*pos + 2] << 8; - *target |= data[*pos + 1] << 16 | (uint16_t)data[*pos] << 24; + *target = data[*pos + 3] | (uint32_t)data[*pos + 2] << 8; + *target |= data[*pos + 1] << 16 | (uint32_t)data[*pos] << 24; #elif __BYTE_ORDER == __BIG_ENDIAN - *target = data[*pos] | (uint16_t)data[*pos + 1] << 8; - *target |= data[*pos + 2] << 16 | (uint16_t)data[*pos + 3] << 24; + *target = data[*pos] | (uint32_t)data[*pos + 1] << 8; + *target |= data[*pos + 2] << 16 | (uint32_t)data[*pos + 3] << 24; #else |