X-Git-Url: https://git.draconx.ca/gitweb/liblbx.git/blobdiff_plain/b42e3c4eadf05be2506e1a1f8deb2cf24064c18b..ab1aa9d00734935b779c5d3af217583b4c36ca6a:/src/byteorder.h diff --git a/src/byteorder.h b/src/byteorder.h index c997b10..4cf2854 100644 --- a/src/byteorder.h +++ b/src/byteorder.h @@ -5,12 +5,32 @@ # include "config.h" #endif +#include + +static inline uint16_t _flip16(uint16_t val) +{ + uint16_t hostval; + int i; + + for (i = 0; i < sizeof val; i++) + ((uint8_t *)&hostval)[i] = ((uint8_t *)&val)[sizeof val - i]; +} + +static inline uint32_t _flip32(uint32_t val) +{ + uint32_t hostval; + int i; + + for (i = 0; i < sizeof val; i++) + ((uint8_t *)&hostval)[i] = ((uint8_t *)&val)[sizeof val - i]; +} + #ifdef WORDS_BIGENDIAN - uint16_t letohs(uint16_t); - uint32_t letohl(uint32_t); +# define letohs(x) _flip16(x) +# define letohl(x) _flip32(x) #else -# define letohs(x) (x) -# define letohl(x) (x) +# define letohs(x) ((uint16_t)(x)) +# define letohl(x) ((uint16_t)(x)) #endif #endif