From: Paul Eggert Date: Thu, 11 Oct 2007 21:43:30 +0000 (-0700) Subject: Simplify and modernize strerror substitute, partly to fix Solaris 8 bug. X-Git-Tag: v0.0~103 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=73f48e6fcc45389a6d7022b7de234d82b97b2f7f;p=gnulib.git Simplify and modernize strerror substitute, partly to fix Solaris 8 bug. * lib/strerror.c: Include always, to test interface, and to remove the need for the dummy. Include intprops.h to compute width instead of doing it ourselves and missing a CHAR_BIT declaration, which broke tar 1.19 on Solaris 8. (strerror): Define it to return NULL if there's no system strerror. (rpl_strerror): Use INT_STRLEN_BOUND to compute bound. Omit !HAVE_STRERROR code. We don't need to worry about supporting ancient pre-strerror Unix systems well any more. Saying "unknown system error" is enough. * lib/string.in.h (strerror): Simplify the ifdef to reflect the simpler strerror.c implementation. * m4/strerror.m4 (gl_FUNC_STRERROR_SEPARATE, gl_PREREQ_STDERROR): Simplify the tests to reflect the simpler strerror implementation. * modules/strerror (Depends-on): Add intprops. --- diff --git a/ChangeLog b/ChangeLog index bb9a66472..bc1abeece 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2007-10-11 Paul Eggert + + Simplify and modernize strerror substitute, partly to fix Solaris 8 bug. + + * lib/strerror.c: Include always, to test interface, + and to remove the need for the dummy. + Include intprops.h to compute width instead of doing it ourselves + and missing a CHAR_BIT declaration, which broke tar 1.19 on Solaris 8. + (strerror): Define it to return NULL if there's no system strerror. + (rpl_strerror): Use INT_STRLEN_BOUND to compute bound. + Omit !HAVE_STRERROR code. We don't need to worry about supporting + ancient pre-strerror Unix systems well any more. Saying "unknown + system error" is enough. + * lib/string.in.h (strerror): Simplify the ifdef to reflect the + simpler strerror.c implementation. + * m4/strerror.m4 (gl_FUNC_STRERROR_SEPARATE, gl_PREREQ_STDERROR): + Simplify the tests to reflect the simpler strerror implementation. + * modules/strerror (Depends-on): Add intprops. + 2007-10-09 Eric Blake Silence test-fpending. diff --git a/lib/strerror.c b/lib/strerror.c index fd5ec1562..9b9ffd104 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -1,7 +1,6 @@ -/* strerror.c --- ANSI C compatible system error routine +/* strerror.c --- POSIX compatible system error routine - Copyright (C) 1986, 1988, 1989, 1991, 2002, 2003, 2006, 2007 Free - Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,61 +17,33 @@ #include +#include + #if REPLACE_STRERROR -# include # include +# include "intprops.h" + # undef strerror +# if ! HAVE_DECL_STRERROR +# define strerror(n) NULL +# endif -char *rpl_strerror (int n) +char * +rpl_strerror (int n) { - static char const fmt[] = "Unknown error (%d)"; - static char mesg[sizeof fmt + sizeof n * CHAR_BIT / 3]; - char *result = strerror (n); if (! result) { + static char const fmt[] = "Unknown error (%d)"; + static char mesg[sizeof fmt + INT_STRLEN_BOUND (n)]; sprintf (mesg, fmt, n); return mesg; } - return result; -} - -#elif !HAVE_STRERROR - -#include -/* Don't include , since it may or may not declare - sys_errlist and its declarations may collide with ours. Just - declare the stuff that we need directly. Standard hosted C89 - implementations define strerror and they don't need this strerror - function, so take some liberties with the standard to cater to - ancient or limited freestanding implementations. */ -int sprintf (char *, char const *, ...); -extern int sys_nerr; -extern char *sys_errlist[]; - -char * -strerror (int n) -{ - static char const fmt[] = "Unknown error (%d)"; - static char mesg[sizeof fmt + sizeof n * CHAR_BIT / 3]; - - if (n < 0 || n >= sys_nerr) - { - sprintf (mesg, fmt, n); - return mesg; - } - else - return sys_errlist[n]; + return result; } -#else - -/* This declaration is solely to ensure that after preprocessing - this file is never empty. */ -typedef int dummy; - #endif diff --git a/lib/string.in.h b/lib/string.in.h index 41e539f23..ba7ca5319 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -544,8 +544,6 @@ extern char * mbstok_r (char *string, const char *delim, char **save_ptr); # if @REPLACE_STRERROR@ # undef strerror # define strerror rpl_strerror -# endif -# if !@HAVE_DECL_STRERROR@ || @REPLACE_STRERROR@ extern char *strerror (int); # endif #elif defined GNULIB_POSIXCHECK diff --git a/m4/strerror.m4 b/m4/strerror.m4 index 52f3e3fdc..f59c71013 100644 --- a/m4/strerror.m4 +++ b/m4/strerror.m4 @@ -1,4 +1,4 @@ -# strerror.m4 serial 4 +# strerror.m4 serial 5 dnl Copyright (C) 2002, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -17,33 +17,33 @@ AC_DEFUN([gl_FUNC_STRERROR], # Like gl_FUNC_STRERROR, except prepare for separate compilation (no AC_LIBOBJ). AC_DEFUN([gl_FUNC_STRERROR_SEPARATE], [ - AC_CHECK_FUNCS_ONCE([strerror]) - gl_PREREQ_STRERROR - if test $ac_cv_func_strerror = no; then - HAVE_DECL_STRERROR=0 - gl_cv_func_working_strerror=no - else - AC_CACHE_CHECK([for working strerror function], - [gl_cv_func_working_strerror], - [AC_RUN_IFELSE( - [AC_LANG_PROGRAM([ -#include - ], [return !*strerror (-2);])], - [gl_cv_func_working_strerror=yes], [gl_cv_func_working_strerror=no], - [dnl assume success except on Interix - AC_EGREP_CPP([assuming success], [ -#ifndef __INTERIX - assuming success -#endif - ], [gl_cv_func_working_strerror=yes], - [gl_cv_func_working_strerror=no])])]) - if test $gl_cv_func_working_strerror = no ; then - REPLACE_STRERROR=1 - fi + AC_CACHE_CHECK([for working strerror function], + [gl_cv_func_working_strerror], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [#include + ], + [return !*strerror (-2);])], + [gl_cv_func_working_strerror=yes], + [gl_cv_func_working_strerror=no], + [dnl Assume crossbuild works if it compiles, except for Interix. + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [#include + #ifdef __INTERIX + Interix is broken; + #endif + ], + [return !*strerror (-2);])], + [gl_cv_func_working_strerror=yes], + [gl_cv_func_working_strerror=no])])]) + if test $gl_cv_func_working_strerror = no ; then + REPLACE_STRERROR=1 + gl_PREREQ_STRERROR fi ]) # Prerequisites of lib/strerror.c. AC_DEFUN([gl_PREREQ_STRERROR], [ - : + AC_CHECK_DECLS([strerror]) ]) diff --git a/modules/strerror b/modules/strerror index 24dacabe1..2e914b345 100644 --- a/modules/strerror +++ b/modules/strerror @@ -6,6 +6,7 @@ lib/strerror.c m4/strerror.m4 Depends-on: +intprops string configure.ac: