From: Antonio Ospite Date: Thu, 8 May 2014 09:22:31 +0000 (+0200) Subject: am7xxx: add a portable_endian.h X-Git-Tag: v0.1.5~9 X-Git-Url: https://git.ao2.it/libam7xxx.git/commitdiff_plain/74fbc97d04c4321dd94790f96e951e2fd2c14664?ds=sidebyside am7xxx: add a portable_endian.h Add a portable_endian.h to define platform specific implementations for the functions found on most unix-like systems in endian.h. --- diff --git a/src/portable_endian.h b/src/portable_endian.h new file mode 100644 index 0000000..1741f18 --- /dev/null +++ b/src/portable_endian.h @@ -0,0 +1,65 @@ +/* + * Public domain, stripped down version of: + * https://gist.github.com/panzi/6856583 + */ + +#ifndef __PORTABLE_ENDIAN_H +#define __PORTABLE_ENDIAN_H + +#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) + +# define __WINDOWS__ + +#endif + +#if defined(__linux__) || defined(__CYGWIN__) + +# include + +#elif defined(__APPLE__) + +# include + +# define htole32(x) OSSwapHostToLittleInt32(x) +# define le32toh(x) OSSwapLittleToHostInt32(x) + +#elif defined(__OpenBSD__) + +# include + +#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) + +# include + +# define le32toh(x) letoh32(x) + +#elif defined(__WINDOWS__) + +# include +# include + +# if BYTE_ORDER == LITTLE_ENDIAN + +# define htole32(x) (x) +# define le32toh(x) (x) + +# elif BYTE_ORDER == BIG_ENDIAN + + /* that would be xbox 360 */ + +# define htole32(x) __builtin_bswap32(x) +# define le32toh(x) __builtin_bswap32(x) + +# else + +# error byte order not supported + +# endif + +#else + +#error platform not supported + +#endif + +#endif /* __PORTABLE_ENDIAN_H */ diff --git a/src/serialize.c b/src/serialize.c index 72e3fd4..61536a0 100644 --- a/src/serialize.c +++ b/src/serialize.c @@ -18,13 +18,7 @@ #include -#ifdef __MINGW32__ -#define le32toh(x) (x) -#define htole32(x) (x) -#else -#include -#endif - +#include "portable_endian.h" #include "serialize.h" uint8_t get_8(uint8_t **bufferp)