# Copyright 2009, Wouter Wijngaards, NLnet Labs.
# BSD licensed.
#
-# Version 5
+# Version 6
+# 2010-02-01 added ACX_CHECK_MEMCMP_SIGNED, AHX_MEMCMP_BROKEN
# 2010-01-20 added AHX_COONFIG_STRLCAT
# 2009-07-14 U_CHAR detection improved for windows crosscompile.
# added ACX_FUNC_MALLOC
# AHX_CONFIG_FLAG_OMITTED - define omitted flag
# AHX_CONFIG_FLAG_EXT - define omitted extension flag
# AHX_CONFIG_EXT_FLAGS - define the stripped extension flags
+# ACX_CHECK_MEMCMP_SIGNED - check if memcmp uses signed characters.
+# AHX_MEMCMP_BROKEN - replace memcmp func for CHECK_MEMCMP_SIGNED.
#
dnl Escape backslashes as \\, for C:\ paths, for the C preprocessor defines.
AHX_CONFIG_FLAG_EXT(-D_LARGEFILE_SOURCE=1)
])
+dnl check if memcmp is using signed characters and replace if so.
+AC_DEFUN([ACX_CHECK_MEMCMP_SIGNED],
+[AC_MSG_CHECKING([if memcmp compares unsigned])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+int main(void)
+{
+ char a = 255, b = 0;
+ if(memcmp(&a, &b, 1) < 0)
+ return 1;
+ return 0;
+}
+]])], [AC_MSG_RESULT([yes]) ],
+[ AC_MSG_RESULT([no])
+ AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes])
+ AC_LIBOBJ([memcmp])
+], [ AC_MSG_RESULT([cross-compile no])
+ AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes])
+ AC_LIBOBJ([memcmp])
+]) ])
+
+dnl define memcmp to its replacement, pass unique id for program as arg
+AC_DEFUN([AHX_MEMCMP_BROKEN], [
+#ifdef MEMCMP_IS_BROKEN
+# ifdef memcmp
+# undef memcmp
+# endif
+#define memcmp memcmp_$1
+int memcmp(const void *x, const void *y, size_t n);
+#endif
+])
+
dnl End of file
--- /dev/null
+/*
+ * memcmp.c: memcmp compat implementation.
+ *
+ * Copyright (c) 2010, NLnet Labs. All rights reserved.
+ *
+ * See LICENSE for the license.
+*/
+
+#include <config.h>
+
+int memcmp(const void *x, const void *y, size_t n);
+
+int memcmp(const void *x, const void *y, size_t n)
+{
+ const uint8_t* x8 = (const uint8_t*)x;
+ const uint8_t* y8 = (const uint8_t*)y;
+ size_t i;
+ for(i=0; i<n; i++) {
+ if(x8[i] < y8[i])
+ return -1;
+ else if(x8[i] > y8[i])
+ return 1;
+ }
+ return 0;
+}
/* Define to the maximum message length to pass to syslog. */
#undef MAXSYSLOGMSGLEN
+/* Define if memcmp() does not compare unsigned bytes */
+#undef MEMCMP_IS_BROKEN
+
/* Define if mkdir has one argument. */
#undef MKDIR_HAS_ONE_ARG
#endif /* IPV6_MIN_MTU */
+#ifdef MEMCMP_IS_BROKEN
+# ifdef memcmp
+# undef memcmp
+# endif
+#define memcmp memcmp_unbound
+int memcmp(const void *x, const void *y, size_t n);
+#endif
+
+
#ifndef HAVE_CTIME_R
#define ctime_r unbound_ctime_r
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
+{ $as_echo "$as_me:$LINENO: checking if memcmp compares unsigned" >&5
+$as_echo_n "checking if memcmp compares unsigned... " >&6; }
+if test "$cross_compiling" = yes; then
+ { $as_echo "$as_me:$LINENO: result: cross-compile no" >&5
+$as_echo "cross-compile no" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define MEMCMP_IS_BROKEN 1
+_ACEOF
+
+ case " $LIBOBJS " in
+ *" memcmp.$ac_objext "* ) ;;
+ *) LIBOBJS="$LIBOBJS memcmp.$ac_objext"
+ ;;
+esac
+
+
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+int main(void)
+{
+ char a = 255, b = 0;
+ if(memcmp(&a, &b, 1) < 0)
+ return 1;
+ return 0;
+}
+
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+ $as_echo "$as_me: program exited with status $ac_status" >&5
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define MEMCMP_IS_BROKEN 1
+_ACEOF
+
+ case " $LIBOBJS " in
+ *" memcmp.$ac_objext "* ) ;;
+ *) LIBOBJS="$LIBOBJS memcmp.$ac_objext"
+ ;;
+esac
+
+
+fi
+rm -rf conftest.dSYM
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
for ac_func in inet_aton
do
ACX_CHECK_NONBLOCKING_BROKEN
ACX_MKDIR_ONE_ARG
ACX_FUNC_IOCTLSOCKET
+ACX_CHECK_MEMCMP_SIGNED
AC_REPLACE_FUNCS(inet_aton)
AC_REPLACE_FUNCS(inet_pton)
AC_REPLACE_FUNCS(inet_ntop)
AHX_CONFIG_W32_SRANDOM
AHX_CONFIG_W32_FD_SET_T
AHX_CONFIG_IPV6_MIN_MTU
+AHX_MEMCMP_BROKEN(unbound)
[
#ifndef HAVE_CTIME_R
1 February 2010: Wouter
- iana portlist updated.
+ - configure test for memcmp portability.
27 January 2010: Wouter
- removed warning on format string in validator error log statement.