[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: unicodeio.c ignores fwrite return value
From: |
Paolo Bonzini |
Subject: |
Re: unicodeio.c ignores fwrite return value |
Date: |
Wed, 12 Nov 2008 16:12:00 +0100 |
User-agent: |
Thunderbird 2.0.0.17 (Macintosh/20080914) |
>> - 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