From a224836798b9290997eba5bd7c64f1cea6c5f535 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Tue, 22 Mar 2016 07:36:54 +0000 Subject: [PATCH 1/2] configure: Detect headers before using them Current logic does not work when system does not have sys/endian.h, since it tried to reuse the cached results from first try of detecting htole64 in sys/endian.h which is 'no' and hence the second try to look into endian.h also comes out negative. So we check for header and then run the test for symbols and these symbols are not standard and we need to define _GNU_SOURCE for it to work, this issue is exposed by systems using musl e.g. Signed-off-by: Khem Raj --- configure.ac | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 4cb56bc..5e23c50 100644 --- a/configure.ac +++ b/configure.ac @@ -69,12 +69,17 @@ AC_FUNC_MALLOC AC_FUNC_REALLOC AC_FUNC_STRTOD AC_CHECK_FUNCS([memchr memmove memset strerror strtol]) -AC_CHECK_DECLS([htole64, le64toh], - [], +AC_CHECK_HEADER([sys/endian.h], [ - AC_CHECK_DECLS([htole64, le64toh], [], [], [#include ]) + AC_CHECK_DECLS([htole64, le64toh], [], [], [#define _GNU_SOURCE 1 #include ]) ], - [#include ]) + [], []) + +AC_CHECK_HEADER([endian.h], + [ + AC_CHECK_DECLS([htole64, le64toh], [], [], [#define _GNU_SOURCE 1 #include ]) + ], + [], []) AC_CONFIG_FILES([Makefile src/Makefile From 5ed67fc86f3b7baaa724c685b9270dbcf16196a9 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Tue, 22 Mar 2016 07:42:39 +0000 Subject: [PATCH 2/2] endian: Use macro bswap_64 instead of __bswap_64 byteswap.h defines then as public APIs on all libc on linux including musl Signed-off-by: Khem Raj --- src/endian.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/endian.c b/src/endian.c index b7724f3..51aea58 100644 --- a/src/endian.c +++ b/src/endian.c @@ -15,6 +15,7 @@ void xle64enc(uint8_t *d, uint64_t n) { #include #ifdef __linux__ #include + #include #else #include #endif @@ -23,7 +24,7 @@ void xle64enc(uint8_t *d, uint64_t n) { # if __BYTE_ORDER == __LITTLE_ENDIAN # define htole64(x) (x) # else -# define htole64(x) __bswap_64 (x) +# define htole64(x) bswap_64 (x) # endif #endif @@ -31,7 +32,7 @@ void xle64enc(uint8_t *d, uint64_t n) { # if __BYTE_ORDER == __LITTLE_ENDIAN # define le64toh(x) (x) # else -# define le64toh(x) __bswap_64 (x) +# define le64toh(x) bswap_64 (x) # endif #endif