diff --git a/configure.ac b/configure.ac index 927319f..9e303fc 100644 --- a/configure.ac +++ b/configure.ac @@ -54,6 +54,12 @@ AC_FUNC_MALLOC AC_FUNC_REALLOC AC_FUNC_STRTOD AC_CHECK_FUNCS([memchr memmove memset strerror strtol]) +AC_CHECK_DECLS([htole64, le64toh], + [], + [ + AC_CHECK_DECLS([htole64, le64toh], [], [], [#include ]) + ], + [#include ]) AC_CONFIG_FILES([Makefile src/Makefile diff --git a/src/endian.c b/src/endian.c index e620631..b7724f3 100644 --- a/src/endian.c +++ b/src/endian.c @@ -19,6 +19,22 @@ void xle64enc(uint8_t *d, uint64_t n) { #include #endif +#if !HAVE_DECL_HTOLE64 +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define htole64(x) (x) +# else +# define htole64(x) __bswap_64 (x) +# endif +#endif + +#if !HAVE_DECL_LE64TOH +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define le64toh(x) (x) +# else +# define le64toh(x) __bswap_64 (x) +# endif +#endif + uint64_t xle64dec(const uint8_t *d) { return le64toh(*(uint64_t*)d); }