From 5d831e6d1b4f0fb62504307aeea2c062e783357e Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Sun, 20 Sep 2015 21:49:33 +0200 Subject: [PATCH] autoconf checks for htole64 and le64toh - addresses #52 --- configure.ac | 6 ++++++ src/endian.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) 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); }