autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proposed Autoconf patch for strerror_r handling


From: Paul Eggert
Subject: proposed Autoconf patch for strerror_r handling
Date: Sun, 21 Oct 2001 00:55:28 -0700 (PDT)

This patch was prompted by a user of tar 1.13.25 who reported that tar
doesn't work on HP-UX 10.20.  It turns out that strerror_r returns int
on that host, but tar's error.c didn't inspect
HAVE_WORKING_STRERROR_R.  Apparently the HAVE_WORKING_STRERROR_R stuff
got lost somehow from recent versions of error.c.

However, when fixing this, I noticed that POSIX 1003.1-200x Draft 7,
which will become the official POSIX standard soon, specifies that
strerror_r must return int, not char *.  So the name
HAVE_WORKING_STRERROR_R isn't correct: it's the 'int' strerror_r
versions that conform to the (next) standard, not the 'char*' ones.

To avoid this problem with the new POSIX standard, I propose that we
rename HAVE_WORKING_STRERROR_R to STRERROR_R_CHAR_P (using the same
naming convention as CLOSEDIR_VOID).  This rename won't affect recent
versions of error.c, since they're broken anyway.  And error.c is the
only consumer of this macro that I know of, so renaming it should be
fine.

Here is a proposed patch to Autoconf to fix this problem, along with a
couple of minor glitches in the neighborhood..  I have already sent
the corresponding error.c patches to Jim Meyering and they'll also
appear in the next version of tar.

2001-10-21  Paul Eggert  <address@hidden>

        * lib/autoconf/functions.m4 (AC_FUNC_STRERROR_R):
        Rename ac_cv_func_strerror_r_works to ac_cv_func_strerror_r_char_p,
        and rename HAVE_WORKING_STRERROR_R to STRERROR_R_CHAR_P, since
        POSIX decided to standardize on the int flavor of strerror_r.
        Always do char* test, as there's no reason not to.
        Assign to a char* var, to catch strerror_r that returns int*.

        * doc/autoconf.texi (Particular Functions):
        Document the above changes.  Also, document the fact that
        AC_FUNC_STRERROR_R defines HAVE_DECL_STRERROR_R.

Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.552
diff -p -u -r1.552 autoconf.texi
--- doc/autoconf.texi   2001/10/20 06:56:45     1.552
+++ doc/autoconf.texi   2001/10/21 07:53:09
@@ -3757,15 +3757,18 @@ variable @code{POW_LIB} to the extra lib
 @defmac AC_FUNC_STRERROR_R
 @acindex FUNC_STRERROR_R
 @cvindex HAVE_STRERROR_R
address@hidden HAVE_WORKING_STRERROR_R
address@hidden HAVE_DECL_STRERROR_R
address@hidden STRERROR_R_CHAR_P
 @c @fuindex strerror_r
 @prindex @code{strerror_r}
-If @code{strerror_r} is available, define @code{HAVE_STRERROR_R}.  If
-its implementation correctly returns a @code{char *}, define
address@hidden  On at least DEC UNIX 4.0[A-D] and HP-UX
-B.10.20, @code{strerror_r} returns @code{int}.  Actually, this tests
-only whether it returns a scalar or an array, but that should be enough.
-This is used by the common @file{error.c}.
+If @code{strerror_r} is available, define @code{HAVE_STRERROR_R}, and if
+it is declared, define @code{HAVE_DECL_STRERROR_R}.  If it returns a
address@hidden *} message, define @code{STRERROR_R_CHAR_P}; otherwise it
+returns an @code{int} error number.  The Thread-Safe Functions option of
address@hidden requires @code{strerror_r} to return @code{int}, but
+many systems (including, for example, version 2.2.4 of the GNU C
+Library) return a @code{char *} value that is not necessarily equal to
+the buffer argument.
 @end defmac
 
 @defmac AC_FUNC_STRFTIME
Index: lib/autoconf/functions.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/functions.m4,v
retrieving revision 1.48
diff -p -u -r1.48 functions.m4
--- lib/autoconf/functions.m4   2001/09/21 16:19:09     1.48
+++ lib/autoconf/functions.m4   2001/10/21 07:37:50
@@ -1216,19 +1216,20 @@ AU_ALIAS([AM_FUNC_STRTOD], [AC_FUNC_STRT
 AC_DEFUN([AC_FUNC_STRERROR_R],
 [AC_CHECK_DECLS([strerror_r])
 AC_CHECK_FUNCS([strerror_r])
-if test $ac_cv_func_strerror_r = yes; then
-  AC_CACHE_CHECK([for working strerror_r],
-                 ac_cv_func_strerror_r_works,
+AC_CACHE_CHECK([whether strerror_r returns char *],
+               ac_cv_func_strerror_r_char_p,
    [
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
-     [[
-       char buf[100];
-       char x = *strerror_r (0, buf, sizeof buf);
-     ]])],
-                      ac_cv_func_strerror_r_works=yes,
-                      ac_cv_func_strerror_r_works=no)
-    if test $ac_cv_func_strerror_r_works = no; then
-      # strerror_r seems not to work, but now we have to choose between
+    ac_cv_func_strerror_r_char_p=no
+    if test $ac_cv_have_decl_strerror_r = yes; then
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
+       [[
+         char buf[100];
+         char x = *strerror_r (0, buf, sizeof buf);
+         char *p = strerror_r (0, buf, sizeof buf);
+       ]])],
+                       ac_cv_func_strerror_r_char_p=yes)
+    else
+      # strerror_r is not declared.  Choose between
       # systems that have relatively inaccessible declarations for the
       # function.  BeOS and DEC UNIX 4.0 fall in this category, but the
       # former has a strerror_r that returns char*, while the latter
@@ -1239,15 +1240,12 @@ if test $ac_cv_func_strerror_r = yes; th
        [[char buf[100];
          char x = *strerror_r (0, buf, sizeof buf);
          exit (!isalpha (x));]])],
-                    ac_cv_func_strerror_r_works=yes,
-                    ac_cv_func_strerror_r_works=no,
-                    ac_cv_func_strerror_r_works=no)
+                    ac_cv_func_strerror_r_char_p=yes, , :)
     fi
   ])
-  if test $ac_cv_func_strerror_r_works = yes; then
-    AC_DEFINE_UNQUOTED([HAVE_WORKING_STRERROR_R], 1,
-                       [Define to 1 if `strerror_r' returns a string.])
-  fi
+if test $ac_cv_func_strerror_r_char_p = yes; then
+  AC_DEFINE([STRERROR_R_CHAR_P], 1,
+           [Define to 1 if strerror_r returns char *.])
 fi
 ])# AC_FUNC_STRERROR_R
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]