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 <ebl...@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 <ebl...@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 <br...@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