diff options
Diffstat (limited to 'include/utils/ByteOrder.h')
-rw-r--r-- | include/utils/ByteOrder.h | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/include/utils/ByteOrder.h b/include/utils/ByteOrder.h index 4c06067..baa3a83 100644 --- a/include/utils/ByteOrder.h +++ b/include/utils/ByteOrder.h @@ -38,6 +38,16 @@ * intent is to allow us to avoid byte swapping on the device. */ +static inline uint32_t android_swap_long(uint32_t v) +{ + return (v<<24) | ((v<<8)&0x00FF0000) | ((v>>8)&0x0000FF00) | (v>>24); +} + +static inline uint16_t android_swap_short(uint16_t v) +{ + return (v<<8) | (v>>8); +} + #define DEVICE_BYTE_ORDER LITTLE_ENDIAN #if BYTE_ORDER == DEVICE_BYTE_ORDER @@ -49,16 +59,6 @@ #else -static inline uint32_t android_swap_long(uint32_t v) -{ - return (v<<24) | ((v<<8)&0x00FF0000) | ((v>>8)&0x0000FF00) | (v>>24); -} - -static inline uint16_t android_swap_short(uint16_t v) -{ - return (v<<8) | (v>>8); -} - #define dtohl(x) (android_swap_long(x)) #define dtohs(x) (android_swap_short(x)) #define htodl(x) (android_swap_long(x)) @@ -66,4 +66,16 @@ static inline uint16_t android_swap_short(uint16_t v) #endif +#if BYTE_ORDER == LITTLE_ENDIAN +#define fromlel(x) (x) +#define fromles(x) (x) +#define tolel(x) (x) +#define toles(x) (x) +#else +#define fromlel(x) (android_swap_long(x)) +#define fromles(x) (android_swap_short(x)) +#define tolel(x) (android_swap_long(x)) +#define toles(x) (android_swap_short(x)) +#endif + #endif // _LIBS_UTILS_BYTE_ORDER_H |