2011-05-20 Eric Blake <eblake@redhat.com>
+ perror: work around FreeBSD bug
+ * m4/perror.m4 (gl_FUNC_PERROR): Also replace perror if strerror_r
+ is broken. Move AC_LIBOBJ...
+ * modules/perror (configure.ac): Here.
+ * doc/posix-functions/perror.texi (perror): Document this.
+ * tests/test-perror2.c (main): Enhance test.
+
test-perror: check for strerror interactions
* tests/macros.h (STREQ) Add macro.
* modules/perror-tests (Files): Add second test.
This function does not support the error values that are specified by POSIX
but not defined by the system, on some platforms:
OpenBSD 4.0, OSF/1 5.1, Cygwin 1.5.x, mingw.
+@item
+This function treats @code{errno} of 0 like failure, although POSIX
+requires that the message declare it as a success, on some platforms:
+FreeBSD 8.2
@end itemize
Portability problems not fixed by Gnulib:
-# perror.m4 serial 1
+# perror.m4 serial 2
dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
[
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
AC_REQUIRE([gl_HEADER_ERRNO_H])
+ AC_REQUIRE([gl_FUNC_STRERROR_R])
if test -n "$ERRNO_H"; then
dnl The system's perror() cannot know about the new errno values we add
dnl to <errno.h>. Replace it.
REPLACE_PERROR=1
- AC_LIBOBJ([perror])
fi
+ case ${gl_cv_func_strerror_r_works-unset} in
+ unset|*yes) ;;
+ *) dnl The system's perror() probably inherits the bugs in the
+ dnl system's strerror_r(). Replace it.
+ REPLACE_PERROR=1 ;;
+ esac
])
configure.ac:
gl_FUNC_PERROR
gl_STRING_MODULE_INDICATOR([perror])
+if test $REPLACE_PERROR = 1; then
+ AC_LIBOBJ([perror])
+fi
Makefile.am:
ASSERT (STREQ (msg4, str4));
}
+ /* Test that perror uses the same message as strerror. */
+ {
+ int errs[] = { EACCES, 0, -3, };
+ int i;
+ for (i = 0; i < SIZEOF (errs); i++)
+ {
+ char buf[256];
+ char *err = strerror (errs[i]);
+
+ ASSERT (err);
+ ASSERT (strlen (err) < sizeof buf);
+ rewind (stderr);
+ ASSERT (ftruncate (fileno (stderr), 0) == 0);
+ errno = errs[i];
+ perror (NULL);
+ ASSERT (!ferror (stderr));
+ rewind (stderr);
+ ASSERT (fgets (buf, sizeof buf, stderr) == buf);
+ ASSERT (strstr (buf, err));
+ }
+ }
+
/* Test that perror reports write failure. */
{
ASSERT (freopen (BASE ".tmp", "r", stderr) == stderr);