X-Git-Url: https://git.ao2.it/libam7xxx.git/blobdiff_plain/8fb663458b08cc5cb79ec824348919ee239b4da3..74fbc97d04c4321dd94790f96e951e2fd2c14664:/src/portable_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 */