>>   - We have a wrapper xprintf() for printf(), because printf has some
>>     errors (like ENOMEM or EILSEQ) which are not stream related and
>>     therefore may not set the stream error indicator. But for fwrite(),
>>     you are sure that if there's an error, ferror (stream) will be true.
>>     Then what's the point of the checking fwrite`s return value, and
>>     what's the point of attribute warn_unused_result in its declaration?
> 
> I agree.  Which suggests not to pollute our code with manual,
> per-use work-arounds.

Besides, as close_stream tells...

  bool some_pending = (__fpending (stream) != 0);
  bool prev_fail = (ferror (stream) != 0);
  bool fclose_fail = (fclose (stream) != 0);

  if (prev_fail || (fclose_fail && (some_pending || errno != EBADF)))
    {
      if (! fclose_fail)
        errno = 0;
      return EOF;
    }

... it makes no sense at all (and gives a false sense of security) to
add the attribute to fwrite if you do not add it to fflush and fclose too.

Paolo


Reply via email to