From eebab307ea36888ccac39a970c56ffbf87d05163 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Wed, 26 Jan 2011 14:31:47 +0200 Subject: [PATCH] endian: autoconf detection for enc/dec functions --- m4/usual.m4 | 21 +++++++++++++++++++++ usual/endian.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/m4/usual.m4 b/m4/usual.m4 index 7fb894c..5f1f4fc 100644 --- a/m4/usual.m4 +++ b/m4/usual.m4 @@ -152,6 +152,27 @@ AC_CHECK_FUNCS(syslog mmap recvmsg sendmsg getpeerucred) ### win32: link with ws2_32 AC_SEARCH_LIBS(WSAGetLastError, ws2_32) AC_FUNC_STRERROR_R +### +AC_MSG_CHECKING([for integer enc/dec functions]) +AC_LINK_IFELSE([ + #include + #ifdef HAVE_SYS_ENDIAN_H + #include + #endif + #ifdef HAVE_ENDIAN_H + #include + #endif + char p[[]] = "01234567"; + int main(void) { + be16enc(p, 0); be32enc(p, 1); be64enc(p, 2); + le16enc(p, 2); le32enc(p, 3); le64enc(p, 4); + return (int)(be16dec(p) + be32dec(p) + be64dec(p)) + + (int)(le16dec(p) + le32dec(p) + le64dec(p)); + } ], +[ AC_MSG_RESULT([found]) + AC_DEFINE([HAVE_ENCDEC_FUNCS], [1], [Define if *enc & *dec functions are available]) ], +[AC_MSG_RESULT([not found])]) + ]) dnl diff --git a/usual/endian.h b/usual/endian.h index 2c4d70b..1da1c09 100644 --- a/usual/endian.h +++ b/usual/endian.h @@ -158,6 +158,8 @@ static inline uint64_t _gen_bswap64(uint64_t x) * Read LE/BE values from memory. */ +#ifndef HAVE_ENCDEC_FUNCS + #define _DEC(name, typ, decode) \ static inline typ name(const void *p) { \ typ tmp; \ @@ -190,4 +192,6 @@ _ENC(le32enc, uint32_t, htole32) _ENC(le64enc, uint64_t, htole64) #undef _ENC +#endif /* !HAVE_ENCDEC_FUNCS */ + #endif /* _USUAL_ENDIAN_H_ */ -- 2.39.5