On 08/30/2010 01:52 PM, Jim Meyering wrote:
fwrite is an exception in that its value really is ignorable,
if you know what you're doing.  Hence, the warn_unused_result
attribute on its declaration is the problem, not gcc, and not
the ignore-value module.

Agreed.  Do we have an open bugzilla against glibc for this yet?

The solution here could be to make gnulib provide a better declaration of
fwrite: one without the offending attribute.  Deprecating ignore-value or
somehow disabling all warn_unused_result attributes would be overkill --
no reason to throw the baby out with the bathwater.

In fact, I think that gnulib could do something like:

static inline int
rpl_fwrite(...)
{
  return fwrite(...);
}
#define fwrite rpl_fwrite

to work around broken glibc headers.

In fact, I'm leaning towards the idea of doing that workaround only if the close-out (or close-in) modules are in use, so that you still get the warning if you aren't using the preferred gnulib idiom for making ignored fwrites safe. That is, the gnulib idiom is that you add:

atexit(close_stdout);

to main(), as the guarantee that all possible code paths will safely detect fwrite() and fflush() failures via ferror(), so that nowhere else in the program needs to bother with the return values of intermediate steps on FILE*.

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

Reply via email to