bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH 1/2] test-perror: relax test to ignore cygwin bug
@ 2011-06-07 22:32 Eric Blake
  2011-06-07 22:32 ` [PATCH 2/2] strerror_r-posix: work around cygwin 1.7.9 Eric Blake
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2011-06-07 22:32 UTC (permalink / raw
  To: bug-gnulib

glibc was not the only platform where fprintf(fopen(,"r"))
fails to detect errors; cygwin 1.7.9 is another culprit
(although it will be fixed for 1.7.10), and I suspect that
several other platforms were failing perror2 for the same
reason.

At this point, there are so many functions affected, and
the way to avoid the bug is easy enough (don't pass bogus
streams to output-producing functions), that I'm not worried
about fixing things other than to document them.

* tests/test-perror2.c (main): Relax test on requiring detection
of stream errors, and use unbuffered stream.
* doc/posix-functions/dprintf.texi (dprintf): Document bug.
* doc/posix-functions/fprintf.texi (fprintf): Likewise.
* doc/posix-functions/fputc.texi (fputc): Likewise.
* doc/posix-functions/fputs.texi (fputs): Likewise.
* doc/posix-functions/fputws.texi (fputws): Likewise.
* doc/posix-functions/fwprintf.texi (fwprintf): Likewise.
* doc/posix-functions/fwrite.texi (fwrite): Likewise.
* doc/posix-functions/getopt.texi (getopt): Likewise.
* doc/posix-functions/perror.texi (perror): Likewise.
* doc/posix-functions/printf.texi (printf): Likewise.
* doc/posix-functions/psiginfo.texi (psiginfo): Likewise.
* doc/posix-functions/psignal.texi (psignal): Likewise.
* doc/posix-functions/putc.texi (putc): Likewise.
* doc/posix-functions/putc_unlocked.texi (putc_unlocked):
Likewise.
* doc/posix-functions/putchar.texi (putchar): Likewise.
* doc/posix-functions/putchar_unlocked.texi (putchar_unlocked):
Likewise.
* doc/posix-functions/puts.texi (puts): Likewise.
* doc/posix-functions/putwc.texi (putwc): Likewise.
* doc/posix-functions/putwchar.texi (putwchar): Likewise.
* doc/posix-functions/vdprintf.texi (vdprintf): Likewise.
* doc/posix-functions/vfprintf.texi (vfprintf): Likewise.
* doc/posix-functions/vfwprintf.texi (vfwprintf): Likewise.
* doc/posix-functions/vprintf.texi (vprintf): Likewise.
* doc/posix-functions/vwprintf.texi (vwprintf): Likewise.
* doc/posix-functions/wordexp.texi (wordexp): Likewise.
* doc/posix-functions/wprintf.texi (wprintf): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
---

See http://sourceware.org/ml/newlib/2011/msg00228.html for today's
patch to cygwin.

 ChangeLog                                 |   34 +++++++++++++++++++++++++++++
 doc/posix-functions/dprintf.texi          |    4 +++
 doc/posix-functions/fprintf.texi          |    2 +-
 doc/posix-functions/fputc.texi            |    4 +++
 doc/posix-functions/fputs.texi            |    4 +++
 doc/posix-functions/fputws.texi           |    4 +++
 doc/posix-functions/fwprintf.texi         |    4 +++
 doc/posix-functions/fwrite.texi           |    4 +++
 doc/posix-functions/getopt.texi           |    4 +++
 doc/posix-functions/perror.texi           |    2 +-
 doc/posix-functions/printf.texi           |    2 +-
 doc/posix-functions/psiginfo.texi         |    3 +-
 doc/posix-functions/psignal.texi          |    2 +-
 doc/posix-functions/putc.texi             |    4 +++
 doc/posix-functions/putc_unlocked.texi    |    4 +++
 doc/posix-functions/putchar.texi          |    4 +++
 doc/posix-functions/putchar_unlocked.texi |    4 +++
 doc/posix-functions/puts.texi             |    4 +++
 doc/posix-functions/putwc.texi            |    4 +++
 doc/posix-functions/putwchar.texi         |    4 +++
 doc/posix-functions/vdprintf.texi         |    4 +++
 doc/posix-functions/vfprintf.texi         |    2 +-
 doc/posix-functions/vfwprintf.texi        |    4 +++
 doc/posix-functions/vprintf.texi          |    2 +-
 doc/posix-functions/vwprintf.texi         |    4 +++
 doc/posix-functions/wordexp.texi          |    4 +++
 doc/posix-functions/wprintf.texi          |    4 +++
 tests/test-perror2.c                      |    6 +++-
 28 files changed, 122 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 59c64ae..870ec73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2011-06-07  Eric Blake  <eblake@redhat.com>
+
+	test-perror: relax test to ignore cygwin bug
+	* tests/test-perror2.c (main): Relax test on requiring detection
+	of stream errors, and use unbuffered stream.
+	* doc/posix-functions/dprintf.texi (dprintf): Document bug.
+	* doc/posix-functions/fprintf.texi (fprintf): Likewise.
+	* doc/posix-functions/fputc.texi (fputc): Likewise.
+	* doc/posix-functions/fputs.texi (fputs): Likewise.
+	* doc/posix-functions/fputws.texi (fputws): Likewise.
+	* doc/posix-functions/fwprintf.texi (fwprintf): Likewise.
+	* doc/posix-functions/fwrite.texi (fwrite): Likewise.
+	* doc/posix-functions/getopt.texi (getopt): Likewise.
+	* doc/posix-functions/perror.texi (perror): Likewise.
+	* doc/posix-functions/printf.texi (printf): Likewise.
+	* doc/posix-functions/psiginfo.texi (psiginfo): Likewise.
+	* doc/posix-functions/psignal.texi (psignal): Likewise.
+	* doc/posix-functions/putc.texi (putc): Likewise.
+	* doc/posix-functions/putc_unlocked.texi (putc_unlocked):
+	Likewise.
+	* doc/posix-functions/putchar.texi (putchar): Likewise.
+	* doc/posix-functions/putchar_unlocked.texi (putchar_unlocked):
+	Likewise.
+	* doc/posix-functions/puts.texi (puts): Likewise.
+	* doc/posix-functions/putwc.texi (putwc): Likewise.
+	* doc/posix-functions/putwchar.texi (putwchar): Likewise.
+	* doc/posix-functions/vdprintf.texi (vdprintf): Likewise.
+	* doc/posix-functions/vfprintf.texi (vfprintf): Likewise.
+	* doc/posix-functions/vfwprintf.texi (vfwprintf): Likewise.
+	* doc/posix-functions/vprintf.texi (vprintf): Likewise.
+	* doc/posix-functions/vwprintf.texi (vwprintf): Likewise.
+	* doc/posix-functions/wordexp.texi (wordexp): Likewise.
+	* doc/posix-functions/wprintf.texi (wprintf): Likewise.
+
 2011-05-22  Bruno Haible  <bruno@clisp.org>

 	strerror: Move AC_LIBOBJ invocations to module description.
diff --git a/doc/posix-functions/dprintf.texi b/doc/posix-functions/dprintf.texi
index dc39022..e267cda 100644
--- a/doc/posix-functions/dprintf.texi
+++ b/doc/posix-functions/dprintf.texi
@@ -24,4 +24,8 @@ dprintf

 Portability problems not fixed by Gnulib:
 @itemize
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/fprintf.texi b/doc/posix-functions/fprintf.texi
index 44bcca3..3948018 100644
--- a/doc/posix-functions/fprintf.texi
+++ b/doc/posix-functions/fprintf.texi
@@ -86,5 +86,5 @@ fprintf
 @item
 Attempting to write to a read-only stream fails with @code{EOF} but
 does not set the error flag for @code{ferror} on some platforms:
-glibc 2.13.
+glibc 2.13, cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/fputc.texi b/doc/posix-functions/fputc.texi
index 9d6c9fd..1b5ba7c 100644
--- a/doc/posix-functions/fputc.texi
+++ b/doc/posix-functions/fputc.texi
@@ -28,4 +28,8 @@ fputc
 @item
 On Windows platforms (excluding Cygwin), this function does not set @code{errno}
 upon failure.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/fputs.texi b/doc/posix-functions/fputs.texi
index 7fc4bf5..a7e79d4 100644
--- a/doc/posix-functions/fputs.texi
+++ b/doc/posix-functions/fputs.texi
@@ -28,4 +28,8 @@ fputs
 @item
 On Windows platforms (excluding Cygwin), this function does not set @code{errno}
 upon failure.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/fputws.texi b/doc/posix-functions/fputws.texi
index f3b2b4e..c842488 100644
--- a/doc/posix-functions/fputws.texi
+++ b/doc/posix-functions/fputws.texi
@@ -18,4 +18,8 @@ fputws
 @item
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/fwprintf.texi b/doc/posix-functions/fwprintf.texi
index 79ffc25..d245890 100644
--- a/doc/posix-functions/fwprintf.texi
+++ b/doc/posix-functions/fwprintf.texi
@@ -18,4 +18,8 @@ fwprintf
 @item
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/fwrite.texi b/doc/posix-functions/fwrite.texi
index 20f7fb8..c03a70c 100644
--- a/doc/posix-functions/fwrite.texi
+++ b/doc/posix-functions/fwrite.texi
@@ -28,4 +28,8 @@ fwrite
 @item
 On Windows platforms (excluding Cygwin), this function does not set @code{errno}
 upon failure.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/getopt.texi b/doc/posix-functions/getopt.texi
index 4067295..bab4922 100644
--- a/doc/posix-functions/getopt.texi
+++ b/doc/posix-functions/getopt.texi
@@ -67,4 +67,8 @@ getopt
 necessarily re-read @env{POSIXLY_CORRECT}.  Solaris @code{getopt} does
 not support either reset method, but does not maintain state that
 needs the extra level of reset.
+@item
+On some platforms, this function does not set the stream error
+indicator on attempts to write to a read-only stream:
+glibc 2.13, Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/perror.texi b/doc/posix-functions/perror.texi
index 167cf39..13231e9 100644
--- a/doc/posix-functions/perror.texi
+++ b/doc/posix-functions/perror.texi
@@ -23,7 +23,7 @@ perror
 @item
 POSIX requires that this function set the stream error bit (detected
 by @code{ferror}) on write failure, but not all platforms do this:
-glibc 2.13.
+glibc 2.13, cygwin 1.7.9.
 @item
 POSIX requires that this function not alter stream orientation, but
 the gnulib replacement locks in byte orientation and fails on wide
diff --git a/doc/posix-functions/printf.texi b/doc/posix-functions/printf.texi
index 8fc8cb0..db7218b 100644
--- a/doc/posix-functions/printf.texi
+++ b/doc/posix-functions/printf.texi
@@ -86,5 +86,5 @@ printf
 @item
 Attempting to write to a read-only stream fails with @code{EOF} but
 does not set the error flag for @code{ferror} on some platforms:
-glibc 2.13.
+glibc 2.13, cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/psiginfo.texi b/doc/posix-functions/psiginfo.texi
index 2e940c0..a0f530b 100644
--- a/doc/posix-functions/psiginfo.texi
+++ b/doc/posix-functions/psiginfo.texi
@@ -14,5 +14,6 @@ psiginfo
 @itemize
 @item
 This function is missing on some platforms:
-glibc 2.3.6, MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, OSF/1 5.1, Cygwin, mingw, Interix 3.5, BeOS.
+glibc 2.3.6, MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, AIX
+5.1, HP-UX 11, OSF/1 5.1, Cygwin 1.7.9, mingw, Interix 3.5, BeOS.
 @end itemize
diff --git a/doc/posix-functions/psignal.texi b/doc/posix-functions/psignal.texi
index 1677949..75e6ed8 100644
--- a/doc/posix-functions/psignal.texi
+++ b/doc/posix-functions/psignal.texi
@@ -14,5 +14,5 @@ psignal
 @itemize
 @item
 This function is missing on some platforms:
-HP-UX 11, Cygwin, mingw, Interix 3.5, BeOS.
+HP-UX 11, Cygwin 1.7.9, mingw, Interix 3.5, BeOS.
 @end itemize
diff --git a/doc/posix-functions/putc.texi b/doc/posix-functions/putc.texi
index d156461..c6a815e 100644
--- a/doc/posix-functions/putc.texi
+++ b/doc/posix-functions/putc.texi
@@ -28,4 +28,8 @@ putc
 @item
 On Windows platforms (excluding Cygwin), this function does not set @code{errno}
 upon failure.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/putc_unlocked.texi b/doc/posix-functions/putc_unlocked.texi
index 0c3381e..4fbf3c4 100644
--- a/doc/posix-functions/putc_unlocked.texi
+++ b/doc/posix-functions/putc_unlocked.texi
@@ -15,4 +15,8 @@ putc_unlocked
 @item
 This function is missing on some platforms:
 mingw.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/putchar.texi b/doc/posix-functions/putchar.texi
index aeb6b43..2ded45a 100644
--- a/doc/posix-functions/putchar.texi
+++ b/doc/posix-functions/putchar.texi
@@ -28,4 +28,8 @@ putchar
 @item
 On Windows platforms (excluding Cygwin), this function does not set @code{errno}
 upon failure.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/putchar_unlocked.texi b/doc/posix-functions/putchar_unlocked.texi
index 5bf55b3..bc9c3b0 100644
--- a/doc/posix-functions/putchar_unlocked.texi
+++ b/doc/posix-functions/putchar_unlocked.texi
@@ -15,4 +15,8 @@ putchar_unlocked
 @item
 This function is missing on some platforms:
 mingw.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/puts.texi b/doc/posix-functions/puts.texi
index ef350ac..31e3f0e 100644
--- a/doc/posix-functions/puts.texi
+++ b/doc/posix-functions/puts.texi
@@ -28,4 +28,8 @@ puts
 @item
 On Windows platforms (excluding Cygwin), this function does not set @code{errno}
 upon failure.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/putwc.texi b/doc/posix-functions/putwc.texi
index 82a8a96..b624b25 100644
--- a/doc/posix-functions/putwc.texi
+++ b/doc/posix-functions/putwc.texi
@@ -18,4 +18,8 @@ putwc
 @item
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/putwchar.texi b/doc/posix-functions/putwchar.texi
index 985759a..28930c4 100644
--- a/doc/posix-functions/putwchar.texi
+++ b/doc/posix-functions/putwchar.texi
@@ -18,4 +18,8 @@ putwchar
 @item
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/vdprintf.texi b/doc/posix-functions/vdprintf.texi
index 20a6ef7..8b06c3e 100644
--- a/doc/posix-functions/vdprintf.texi
+++ b/doc/posix-functions/vdprintf.texi
@@ -42,4 +42,8 @@ vdprintf

 Portability problems not fixed by Gnulib:
 @itemize
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/vfprintf.texi b/doc/posix-functions/vfprintf.texi
index c6fab25..4999fb5 100644
--- a/doc/posix-functions/vfprintf.texi
+++ b/doc/posix-functions/vfprintf.texi
@@ -86,5 +86,5 @@ vfprintf
 @item
 Attempting to write to a read-only stream fails with @code{EOF} but
 does not set the error flag for @code{ferror} on some platforms:
-glibc 2.13.
+glibc 2.13, cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/vfwprintf.texi b/doc/posix-functions/vfwprintf.texi
index e018cf5..143704b 100644
--- a/doc/posix-functions/vfwprintf.texi
+++ b/doc/posix-functions/vfwprintf.texi
@@ -18,4 +18,8 @@ vfwprintf
 @item
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/vprintf.texi b/doc/posix-functions/vprintf.texi
index 21d4bc6..7534e01 100644
--- a/doc/posix-functions/vprintf.texi
+++ b/doc/posix-functions/vprintf.texi
@@ -86,5 +86,5 @@ vprintf
 @item
 Attempting to write to a read-only stream fails with @code{EOF} but
 does not set the error flag for @code{ferror} on some platforms:
-glibc 2.13.
+glibc 2.13, cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/vwprintf.texi b/doc/posix-functions/vwprintf.texi
index e82834a..9f3e3b8 100644
--- a/doc/posix-functions/vwprintf.texi
+++ b/doc/posix-functions/vwprintf.texi
@@ -22,4 +22,8 @@ vwprintf
 @item
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/wordexp.texi b/doc/posix-functions/wordexp.texi
index f5d9eaf..6787200 100644
--- a/doc/posix-functions/wordexp.texi
+++ b/doc/posix-functions/wordexp.texi
@@ -15,4 +15,8 @@ wordexp
 @item
 This function is missing on some platforms:
 MacOS X 10.3, OpenBSD 3.8, IRIX 5.3, Cygwin 1.5.x, mingw, Interix 3.5, BeOS.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/doc/posix-functions/wprintf.texi b/doc/posix-functions/wprintf.texi
index 885dd8b..330ca23 100644
--- a/doc/posix-functions/wprintf.texi
+++ b/doc/posix-functions/wprintf.texi
@@ -22,4 +22,8 @@ wprintf
 @item
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
+@item
+On some platforms, this function does not set @code{errno} or the
+stream error indicator on attempts to write to a read-only stream:
+Cygwin 1.7.9.
 @end itemize
diff --git a/tests/test-perror2.c b/tests/test-perror2.c
index 3aab640..e230f92 100644
--- a/tests/test-perror2.c
+++ b/tests/test-perror2.c
@@ -116,12 +116,14 @@ main (void)
   /* Test that perror reports write failure.  */
   {
     ASSERT (freopen (BASE ".tmp", "r", stderr) == stderr);
-    ASSERT (setvbuf (stderr, NULL, _IOLBF, BUFSIZ) == 0);
+    ASSERT (setvbuf (stderr, NULL, _IONBF, BUFSIZ) == 0);
     errno = -1;
     ASSERT (!ferror (stderr));
     perror (NULL);
-    ASSERT (errno > 0);
 #if 0
+    /* Commented out until cygwin behaves:
+       http://sourceware.org/ml/newlib/2011/msg00228.html */
+    ASSERT (errno > 0);
     /* Commented out until glibc behaves:
        http://sourceware.org/bugzilla/show_bug.cgi?id=12792 */
     ASSERT (ferror (stderr));
-- 
1.7.4.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] strerror_r-posix: work around cygwin 1.7.9
  2011-06-07 22:32 [PATCH 1/2] test-perror: relax test to ignore cygwin bug Eric Blake
@ 2011-06-07 22:32 ` Eric Blake
  2011-06-08 10:36   ` Bruno Haible
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2011-06-07 22:32 UTC (permalink / raw
  To: bug-gnulib

Cygwin __xpg_strerror_r clobbers strerror, until cygwin 1.7.10; in
this case, we must replace strerror, but there was nothing in
strerror.m4 finding fault with cygwin's native strerror.  Solve
this by splitting strerror_r.m4 into two parts, one for probing
for the strerror_r bug, and one for replacing strerror_r based
on the presence of bugs unrelated to signature issues; that way,
the 'strerror' module in isolation will not replace strerror, but
if strerror_r is in use for any other reason, then the two use
separate buffers.

Note that cygwin's strerror is thread-safe while the gnulib
replacement is not; but this is no worse than any other
platform where strerror is not thread-safe; in a single-threaded
program, the difference is not observable, and in a multi-threaded
program, you really shouldn't be using strerror in the first place.

Also note that this ends up replacing glibc 2.13 strerror as it
deems __xpg_strerror_r broken on that platform, which isn't
technically necessary for strerror, but doesn't hurt too much.
Meanwhile, glibc 2.14 fixed __xpg_strerror_r, and strerror is not
replaced in that scenario.

* m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Split...
(gl_FUNC_STRERROR_R_WORKS): ...into new macro, to detect Cygwin
bug without replacing strerror_r.
* m4/strerror.m4 (gl_FUNC_STRERROR): Replace strerror if
strerror_r is buggy, but without requiring strerror_r compilation.
* doc/posix-functions/strerror_r.texi (strerror_r): Fix docs.

Signed-off-by: Eric Blake <eblake@redhat.com>
---

Tested on cygwin 1.7.9 and glibc 2.13:

strerror in isolation - no replacements
strerror_r-posix in isolation - strerror_r replaced
perror, strerror, strerror_r-posix together - strerror and strerror_r
 replaced, all tests pass

and on cygwin CVS (will become 1.7.10) and glibc 2.14:

strerror in isolation - no replacements
strerror_r-posix in isolation - strerror_r replaced
perror, strerror, strerror_r-posix together - only strerror_r
 replaced, all tests pass

Committing this requires that Bruno's fix for strerror to move
AC_LIBOBJ to the modules file already be applied, so I've
pushed that one (as well as the trivial modules/perror change)
in the process.

Now to go investigate the MacOS failures...

 ChangeLog                           |    8 +++
 doc/posix-functions/strerror_r.texi |    4 --
 m4/strerror.m4                      |    9 +++-
 m4/strerror_r.m4                    |   90 +++++++++++++++++++++++++++--------
 4 files changed, 86 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 870ec73..af21155 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2011-06-07  Eric Blake  <eblake@redhat.com>

+	strerror_r-posix: work around cygwin 1.7.9
+	* m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Split...
+	(gl_FUNC_STRERROR_R_WORKS): ...into new macro, to detect Cygwin
+	bug without replacing strerror_r.
+	* m4/strerror.m4 (gl_FUNC_STRERROR): Replace strerror if
+	strerror_r is buggy, but without requiring strerror_r compilation.
+	* doc/posix-functions/strerror_r.texi (strerror_r): Fix docs.
+
 	test-perror: relax test to ignore cygwin bug
 	* tests/test-perror2.c (main): Relax test on requiring detection
 	of stream errors, and use unbuffered stream.
diff --git a/doc/posix-functions/strerror_r.texi b/doc/posix-functions/strerror_r.texi
index e0f19c0..4169ca9 100644
--- a/doc/posix-functions/strerror_r.texi
+++ b/doc/posix-functions/strerror_r.texi
@@ -64,8 +64,4 @@ strerror_r

 Portability problems not fixed by Gnulib:
 @itemize
-@item
-Calling this function can clobber the buffer used by @code{strerror}
-on some platforms:
-Cygwin 1.7.9.
 @end itemize
diff --git a/m4/strerror.m4 b/m4/strerror.m4
index 25edd91..de4ba96 100644
--- a/m4/strerror.m4
+++ b/m4/strerror.m4
@@ -1,4 +1,4 @@
-# strerror.m4 serial 12
+# strerror.m4 serial 13
 dnl Copyright (C) 2002, 2007-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,
@@ -8,6 +8,9 @@ AC_DEFUN([gl_FUNC_STRERROR],
 [
   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
   AC_REQUIRE([gl_HEADER_ERRNO_H])
+  m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
+    AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
+  ])
   if test -z "$ERRNO_H"; then
     AC_CACHE_CHECK([for working strerror function],
      [gl_cv_func_working_strerror],
@@ -32,6 +35,10 @@ AC_DEFUN([gl_FUNC_STRERROR],
       dnl integers. Replace it.
       REPLACE_STRERROR=1
     fi
+    dnl If the system's strerror_r clobbers strerror, we must replace strerror.
+    case $gl_cv_func_strerror_r_works in
+      *no) REPLACE_STRERROR=1 ;;
+    esac
   else
     dnl The system's strerror() cannot know about the new errno values we add
     dnl to <errno.h>. Replace it.
diff --git a/m4/strerror_r.m4 b/m4/strerror_r.m4
index 1c0af36..c1d1a8e 100644
--- a/m4/strerror_r.m4
+++ b/m4/strerror_r.m4
@@ -1,4 +1,4 @@
-# strerror_r.m4 serial 9
+# strerror_r.m4 serial 10
 dnl Copyright (C) 2002, 2007-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,
@@ -6,9 +6,7 @@ dnl with or without modifications, as long as this notice is preserved.

 AC_DEFUN([gl_FUNC_STRERROR_R],
 [
-  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
-  AC_REQUIRE([gl_HEADER_ERRNO_H])
-  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])

   dnl Persuade Solaris <string.h> to declare strerror_r().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
@@ -20,7 +18,40 @@ AC_DEFUN([gl_FUNC_STRERROR_R],
     HAVE_DECL_STRERROR_R=0
   fi

-  AC_CHECK_FUNCS([strerror_r])
+  if test $ac_cv_func_strerror_r = yes; then
+    if test -z "$ERRNO_H"; then
+      if test $gl_cv_func_strerror_r_posix_signature = yes; then
+        case "$gl_cv_func_strerror_r_works" in
+          dnl The system's strerror_r has bugs.  Replace it.
+          *no) REPLACE_STRERROR_R=1 ;;
+        esac
+      else
+        dnl The system's strerror() has a wrong signature. Replace it.
+        REPLACE_STRERROR_R=1
+      fi
+    else
+      dnl The system's strerror_r() cannot know about the new errno values we
+      dnl add to <errno.h>. Replace it.
+      REPLACE_STRERROR_R=1
+    fi
+  fi
+])
+
+# Prerequisites of lib/strerror_r.c.
+AC_DEFUN([gl_PREREQ_STRERROR_R], [
+  AC_CHECK_FUNCS_ONCE([catgets])
+  :
+])
+
+# Detect if strerror_r works, but without affecting whether a replacement
+# strerror_r will be used.
+AC_DEFUN([gl_FUNC_STRERROR_R_WORKS],
+[
+  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
+  AC_REQUIRE([gl_HEADER_ERRNO_H])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+  AC_CHECK_FUNCS_ONCE([strerror_r])
   if test $ac_cv_func_strerror_r = yes; then
     if test -z "$ERRNO_H"; then
       dnl The POSIX prototype is:  int strerror_r (int, char *, size_t);
@@ -85,25 +116,44 @@ changequote(,)dnl
 changequote([,])dnl
              ])
           ])
-        case "$gl_cv_func_strerror_r_works" in
-          *no) REPLACE_STRERROR_R=1 ;;
-        esac
       else
-        dnl The system's strerror() has a wrong signature. Replace it.
-        REPLACE_STRERROR_R=1
+        dnl The system's strerror() has a wrong signature.
         dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
         AC_CHECK_FUNCS([__xpg_strerror_r])
+        dnl glibc < 2.14 does not populate buf on failure
+        dnl cygwin < 1.7.10 clobbers strerror
+        if test $ac_cv_func___xpg_strerror_r = yes; then
+          AC_CACHE_CHECK([whether strerror_r works],
+            [gl_cv_func_strerror_r_works],
+            [AC_RUN_IFELSE(
+               [AC_LANG_PROGRAM(
+                  [[#include <errno.h>
+                    #include <string.h>
+                    extern int __xpg_strerror_r(int, char *, size_t);
+                  ]],
+                  [[int result = 0;
+                    char buf[256] = "^";
+                    char copy[256];
+                    char *str = strerror (-1);
+                    strcpy (copy, str);
+                    if (__xpg_strerror_r (-2, buf, 1) == 0)
+                      result |= 1;
+                    if (*buf)
+                      result |= 2;
+                    __xpg_strerror_r (-2, buf, 256);
+                    if (strcmp (str, copy))
+                      result |= 4;
+                    return result;
+                  ]])],
+               [gl_cv_func_strerror_r_works=yes],
+               [gl_cv_func_strerror_r_works=no],
+               [dnl guess no on all platforms that have __xpg_strerror_r,
+                dnl at least until fixed glibc and cygwin are more common
+                gl_cv_func_strerror_r_works="guessing no"
+               ])
+            ])
+        fi
       fi
-    else
-      dnl The system's strerror_r() cannot know about the new errno values we
-      dnl add to <errno.h>. Replace it.
-      REPLACE_STRERROR_R=1
     fi
   fi
 ])
-
-# Prerequisites of lib/strerror_r.c.
-AC_DEFUN([gl_PREREQ_STRERROR_R], [
-  AC_CHECK_FUNCS_ONCE([catgets])
-  :
-])
-- 
1.7.4.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] strerror_r-posix: work around cygwin 1.7.9
  2011-06-07 22:32 ` [PATCH 2/2] strerror_r-posix: work around cygwin 1.7.9 Eric Blake
@ 2011-06-08 10:36   ` Bruno Haible
  2011-06-08 11:12     ` Eric Blake
  0 siblings, 1 reply; 4+ messages in thread
From: Bruno Haible @ 2011-06-08 10:36 UTC (permalink / raw
  To: bug-gnulib; +Cc: Eric Blake

Hi Eric,

> the 'strerror' module in isolation will not replace strerror, but
> if strerror_r is in use for any other reason, then the two use
> separate buffers.

Very nice. Good improvement.

I'm applying a couple of follow-up tweaks:
  - In gl_FUNC_STRERROR, we don't need to emit code in configure that tests
    the value of gl_cv_func_strerror_r_works if that variable cannot have
    been set.
  - gl_FUNC_STRERROR_R_WORKS does not need to require gl_HEADER_STRING_H_DEFAULTS,
    since it doesn't set HAVE_* or REPLACE_* variables. It's gl_FUNC_STRERROR_R
    which needs to require it.
  - gl_PREREQ_STRERROR_R needs to test whether __xpg_strerror_r exists, since
    lib/strerror_r.c tests HAVE___XPG_STRERROR_R. Until two weeks ago, there
    was the assumption that it had already been tested by gl_FUNC_STRERROR_R,
    but that's not the case any more since we have added the 'test -z "$ERRNO_H"'
    and since the list of platforms that have __xpg_strerror_r now includes
    Cygwin (for which "$ERRNO_H" ends up non-empty).
  - Fix a couple of unclear comments.


2011-06-08  Bruno Haible  <bruno@clisp.org>

	strerror_r-posix: Tweaks.
	* m4/strerror.m4 (gl_FUNC_STRERROR): Omit the code that tests
	gl_cv_func_strerror_r_works if gl_FUNC_STRERROR_R_WORKS is not present.
	* m4/strerror_r.m4 (gl_FUNC_STRERROR_R_WORKS): Fix AC_CACHE_CHECK
	message. Move gl_HEADER_STRING_H_DEFAULTS invocation from here...
	(gl_FUNC_STRERROR_R): ... to here.
	(gl_PREREQ_STRERROR_R): Test for __xpg_strerror_r.

--- m4/strerror.m4.orig	Wed Jun  8 12:21:39 2011
+++ m4/strerror.m4	Wed Jun  8 11:52:01 2011
@@ -35,10 +35,13 @@
       dnl integers. Replace it.
       REPLACE_STRERROR=1
     fi
-    dnl If the system's strerror_r clobbers strerror, we must replace strerror.
-    case $gl_cv_func_strerror_r_works in
-      *no) REPLACE_STRERROR=1 ;;
-    esac
+    m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
+      dnl If the system's strerror_r or __xpg_strerror_r clobbers strerror's
+      dnl buffer, we must replace strerror.
+      case "$gl_cv_func_strerror_r_works" in
+        *no) REPLACE_STRERROR=1 ;;
+      esac
+    ])
   else
     dnl The system's strerror() cannot know about the new errno values we add
     dnl to <errno.h>. Replace it.
--- m4/strerror_r.m4.orig	Wed Jun  8 12:21:39 2011
+++ m4/strerror_r.m4	Wed Jun  8 12:00:47 2011
@@ -6,6 +6,7 @@
 
 AC_DEFUN([gl_FUNC_STRERROR_R],
 [
+  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
   AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
 
   dnl Persuade Solaris <string.h> to declare strerror_r().
@@ -26,7 +27,7 @@
           *no) REPLACE_STRERROR_R=1 ;;
         esac
       else
-        dnl The system's strerror() has a wrong signature. Replace it.
+        dnl The system's strerror_r() has a wrong signature. Replace it.
         REPLACE_STRERROR_R=1
       fi
     else
@@ -39,15 +40,15 @@
 
 # Prerequisites of lib/strerror_r.c.
 AC_DEFUN([gl_PREREQ_STRERROR_R], [
+  dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
+  AC_CHECK_FUNCS([__xpg_strerror_r])
   AC_CHECK_FUNCS_ONCE([catgets])
-  :
 ])
 
 # Detect if strerror_r works, but without affecting whether a replacement
 # strerror_r will be used.
 AC_DEFUN([gl_FUNC_STRERROR_R_WORKS],
 [
-  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
   AC_REQUIRE([gl_HEADER_ERRNO_H])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
 
@@ -120,10 +121,10 @@
         dnl The system's strerror() has a wrong signature.
         dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
         AC_CHECK_FUNCS([__xpg_strerror_r])
-        dnl glibc < 2.14 does not populate buf on failure
-        dnl cygwin < 1.7.10 clobbers strerror
+        dnl In glibc < 2.14, __xpg_strerror_r does not populate buf on failure.
+        dnl In cygwin < 1.7.10, __xpg_strerror_r clobbers strerror's buffer.
         if test $ac_cv_func___xpg_strerror_r = yes; then
-          AC_CACHE_CHECK([whether strerror_r works],
+          AC_CACHE_CHECK([whether __xpg_strerror_r works],
             [gl_cv_func_strerror_r_works],
             [AC_RUN_IFELSE(
                [AC_LANG_PROGRAM(
@@ -147,8 +148,8 @@
                   ]])],
                [gl_cv_func_strerror_r_works=yes],
                [gl_cv_func_strerror_r_works=no],
-               [dnl guess no on all platforms that have __xpg_strerror_r,
-                dnl at least until fixed glibc and cygwin are more common
+               [dnl Guess no on all platforms that have __xpg_strerror_r,
+                dnl at least until fixed glibc and cygwin are more common.
                 gl_cv_func_strerror_r_works="guessing no"
                ])
             ])

-- 
In memoriam Larisa Yudina <http://en.wikipedia.org/wiki/Larisa_Yudina>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] strerror_r-posix: work around cygwin 1.7.9
  2011-06-08 10:36   ` Bruno Haible
@ 2011-06-08 11:12     ` Eric Blake
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2011-06-08 11:12 UTC (permalink / raw
  To: Bruno Haible; +Cc: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 3712 bytes --]

On 06/08/2011 04:36 AM, Bruno Haible wrote:
> Hi Eric,
> 
>> the 'strerror' module in isolation will not replace strerror, but
>> if strerror_r is in use for any other reason, then the two use
>> separate buffers.
> 
> Very nice. Good improvement.
> 
> I'm applying a couple of follow-up tweaks:

Thanks.  I've got one more, moving some prereq code out of strerror into
strerror-override (and particularly needed to make strerror_r work on
mingw, if I understand correctly, although I have not yet tested mingw,
so there may be more fallout).  See below.

>   - gl_PREREQ_STRERROR_R needs to test whether __xpg_strerror_r exists, since
>     lib/strerror_r.c tests HAVE___XPG_STRERROR_R. Until two weeks ago, there
>     was the assumption that it had already been tested by gl_FUNC_STRERROR_R,
>     but that's not the case any more since we have added the 'test -z "$ERRNO_H"'
>     and since the list of platforms that have __xpg_strerror_r now includes
>     Cygwin (for which "$ERRNO_H" ends up non-empty).

Actually, "$ERRNO_H" is non-empty on cygwin 1.5, but that also lacks
__xpg_strerror_r.  Cygwin 1.7 does not need a replacement <errno.h>.

diff --git c/ChangeLog i/ChangeLog
index d57fd3f..7e9ad87 100644
--- c/ChangeLog
+++ i/ChangeLog
@@ -1,3 +1,11 @@
+2011-06-08  Eric Blake  <eblake@redhat.com>
+
+	strerror: simplify replacement
+	* m4/strerror.m4 (gl_PREREQ_STRERROR): Delete.
+	* modules/strerror (configure.ac): No prereqs needed here...
+	* modules/strerror-override (configure.ac): ...but this needs it.
+	(Files): Add file for needed prereq macro.
+
 2011-06-08  Bruno Haible  <bruno@clisp.org>

 	strerror_r-posix: Tweaks.
diff --git c/m4/strerror.m4 i/m4/strerror.m4
index 1ae1a2d..048b03c 100644
--- c/m4/strerror.m4
+++ i/m4/strerror.m4
@@ -1,4 +1,4 @@
-# strerror.m4 serial 13
+# strerror.m4 serial 14
 dnl Copyright (C) 2002, 2007-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,
@@ -48,16 +48,3 @@ AC_DEFUN([gl_FUNC_STRERROR],
     REPLACE_STRERROR=1
   fi
 ])
-
-# Prerequisites of lib/strerror.c.
-AC_DEFUN([gl_PREREQ_STRERROR], [
-  AC_CHECK_DECLS([strerror])
-  AC_CHECK_HEADERS_ONCE([sys/socket.h])
-  if test $ac_cv_header_sys_socket_h != yes; then
-    dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
-    dnl the check for those headers unconditional; yet cygwin reports
-    dnl that the headers are present but cannot be compiled (since on
-    dnl cygwin, all socket information should come from sys/socket.h).
-    AC_CHECK_HEADERS([winsock2.h])
-  fi
-])
diff --git c/modules/strerror i/modules/strerror
index a0b7014..1d60662 100644
--- c/modules/strerror
+++ i/modules/strerror
@@ -16,7 +16,6 @@ configure.ac:
 gl_FUNC_STRERROR
 if test $REPLACE_STRERROR = 1; then
   AC_LIBOBJ([strerror])
-  gl_PREREQ_STRERROR
 fi
 gl_MODULE_INDICATOR([strerror])
 gl_STRING_MODULE_INDICATOR([strerror])
diff --git c/modules/strerror-override i/modules/strerror-override
index a31e8a1..bbdf7b8 100644
--- c/modules/strerror-override
+++ i/modules/strerror-override
@@ -4,6 +4,7 @@ strerror_override() function: provide strings for
gnulib-specific errno values
 Files:
 lib/strerror-override.h
 lib/strerror-override.c
+m4/sys_socket_h.m4

 Depends-on:
 errno
@@ -12,6 +13,7 @@ configure.ac:
 AC_REQUIRE([gl_HEADER_ERRNO_H])
 if test -n "$ERRNO_H"; then
   AC_LIBOBJ([strerror-override])
+  gl_PREREQ_SYS_H_WINSOCK2
 fi

 Makefile.am:


-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-08 11:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-07 22:32 [PATCH 1/2] test-perror: relax test to ignore cygwin bug Eric Blake
2011-06-07 22:32 ` [PATCH 2/2] strerror_r-posix: work around cygwin 1.7.9 Eric Blake
2011-06-08 10:36   ` Bruno Haible
2011-06-08 11:12     ` Eric Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).