endian: autoconf detection for enc/dec functions
authorMarko Kreen <markokr@gmail.com>
Wed, 26 Jan 2011 12:31:47 +0000 (14:31 +0200)
committerMarko Kreen <markokr@gmail.com>
Wed, 26 Jan 2011 12:31:47 +0000 (14:31 +0200)
m4/usual.m4
usual/endian.h

index 7fb894cb113fd17bf277dafe0e5cf7510ca294f8..5f1f4fccc042c94fcb98c0cbd961b416f3e23186 100644 (file)
@@ -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 <sys/types.h>
+  #ifdef HAVE_SYS_ENDIAN_H
+  #include <sys/endian.h>
+  #endif
+  #ifdef HAVE_ENDIAN_H
+  #include <endian.h>
+  #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
index 2c4d70be3ffe31cb627d27a3a28acf1b08dea2ad..1da1c092659d6dc2802bd0579382c7409e54065f 100644 (file)
@@ -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_ */