[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AC_FUNC_STRTOD
From: |
Bruno Haible |
Subject: |
Re: AC_FUNC_STRTOD |
Date: |
Sat, 28 Aug 2010 12:56:21 +0200 |
User-agent: |
KMail/1.9.9 |
Paolo Bonzini wrote on 2010-06-15:
> > - AC_FUNC_STRNLEN
>
> This maybe falls in the same group as AC_FUNC_MALLOC/AC_FUNC_REALLOC.
OK, let's leave it in Autoconf. But the cross-compilation guess is too
pessimistic for gnulib habits: we haven't seen the AIX bug on any system
except on AIX. In particular, it's bad to guess "no" for embedded glibc
systems because that increases the size of compiled executables.
Here is a proposed patch.
2010-08-28 Bruno Haible <address@hidden>
strnlen: Improve cross-compilation guess.
* m4/strnlen.m4 (gl_FUNC_STRNLEN): Require AC_CANONICAL_HOST. Inline
the definition of AC_FUNC_STRNLEN, with an improved cross-compilation
guess.
--- m4/strnlen.m4.orig Sat Aug 28 12:51:10 2010
+++ m4/strnlen.m4 Sat Aug 28 12:44:49 2010
@@ -1,4 +1,4 @@
-# strnlen.m4 serial 12
+# strnlen.m4 serial 13
dnl Copyright (C) 2002-2003, 2005-2007, 2009-2010 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
@@ -8,6 +8,7 @@
AC_DEFUN([gl_FUNC_STRNLEN],
[
AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
dnl Persuade glibc <string.h> to declare strnlen().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
@@ -16,11 +17,34 @@
if test $ac_cv_have_decl_strnlen = no; then
HAVE_DECL_STRNLEN=0
else
- AC_FUNC_STRNLEN
- dnl Note: AC_FUNC_STRNLEN does AC_LIBOBJ([strnlen]).
- if test $ac_cv_func_strnlen_working = no; then
- REPLACE_STRNLEN=1
- fi
+ AC_CACHE_CHECK([for working strnlen], [gl_cv_func_strnlen_working],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [AC_INCLUDES_DEFAULT],
+ [[#define S "foobar"
+ #define S_LEN (sizeof S - 1)
+ /* At least one implementation is buggy: that of AIX 4.3 would
+ give strnlen (S, 1) == 3. */
+ int i;
+ for (i = 0; i < S_LEN + 1; ++i)
+ {
+ int expected = i <= S_LEN ? i : S_LEN;
+ if (strnlen (S, i) != expected)
+ return 1;
+ }
+ return 0;
+ ]])],
+ [gl_cv_func_strnlen_working=yes],
+ [gl_cv_func_strnlen_working=no],
+ [# Guess no on AIX systems, yes otherwise.
+ case "$host_os" in
+ aix*) gl_cv_func_strnlen_working="guessing no";;
+ *) gl_cv_func_strnlen_working="guessing yes";;
+ esac
+ ])])
+ case "$gl_cv_func_strnlen_working" in
+ *no) REPLACE_STRNLEN=1 ;;
+ esac
fi
if test $HAVE_DECL_STRNLEN = 0 || test $REPLACE_STRNLEN = 1; then
AC_LIBOBJ([strnlen])