I've tried out the following proposed patch with Emacs. However, I'm no expert with C++ and the C++ parts of it need another pair of eyes to look at.
A similar fix is needed for fwrite_unlocked but I figured one function at a time. ---- diff --git a/ChangeLog b/ChangeLog index 1b42d3c..a1ff2b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2011-03-19 Paul Eggert <egg...@cs.ucla.edu> + + stdio: don't require ignore_value around fwrite + + This patch works around libc bug 11959 + <http://sources.redhat.com/bugzilla/show_bug.cgi?id=11959>. + Without this patch, applications must often write + ignore_value (fwrite (...)) even though the ignore_value is + not helpful here. It's common to write many objects, using + fwrite/printf/etc., and then use ferror to detect output error. + + I considered making this patch optional, but decided against it, + because libc is obviously being inconsistent here: there is no + reason libc should insist that user code must inspect fwrite + return's value without also insisting that it inspect printf's, + putchar's, etc. If user code wants to have a strict style where + all these functions' values are checked (so that ferror need not + be checked), we could add support for that style in a new gnulib + module, but in the meantime it's better to be consistent and to + support common usage. + + * lib/stdio.in.h (rpl_fwrite): Define this wrapper around fwrite, + to work around libc bug 11959, if __USE_FORTIFY_LEVEL indicates + that we are compiling in checking mode, and if not already + wrapping fwrite for some other reason. + (GNULIB_inline_rpl_fwrite): New macro, defined to 1 if this new + wrapper is in use. + (fwrite): Adjust to the possibility that this new wrapper is in use. + 2011-03-19 Jim Meyering <meyer...@redhat.com> maint.mk: fix po-file syntax-check rule diff --git a/lib/stdio.in.h b/lib/stdio.in.h index b5083d1..3ceb98a 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -481,22 +481,39 @@ _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB " "use ftello function for handling of large files"); #endif +#if (0 < __USE_FORTIFY_LEVEL \ + && ! (@GNULIB_FWRITE@ \ + && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)) +# define GNULIB_inline_rpl_fwrite 1 +static inline size_t _GL_ARG_NONNULL ((1, 4)) +rpl_fwrite (const void *ptr, size_t s, size_t n, FILE *stream) +{ + size_t r = fwrite (ptr, s, n, stream); + (void) r; + return r; +} +#endif -#if @GNULIB_FWRITE@ -# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ +#if @GNULIB_FWRITE@ || GNULIB_inline_rpl_fwrite +# if ((@REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@) \ + || GNULIB_inline_rpl_fwrite) # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # undef fwrite # define fwrite rpl_fwrite # endif +# if !GNULIB_inline_rpl_fwrite _GL_FUNCDECL_RPL (fwrite, size_t, (const void *ptr, size_t s, size_t n, FILE *stream) _GL_ARG_NONNULL ((1, 4))); +# endif _GL_CXXALIAS_RPL (fwrite, size_t, (const void *ptr, size_t s, size_t n, FILE *stream)); # else _GL_CXXALIAS_SYS (fwrite, size_t, (const void *ptr, size_t s, size_t n, FILE *stream)); # endif +#endif +#if @GNULIB_FWRITE@ _GL_CXXALIASWARN (fwrite); #endif