bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unicodeio.c ignores fwrite return value


From: Jim Meyering
Subject: Re: unicodeio.c ignores fwrite return value
Date: Wed, 12 Nov 2008 14:50:28 +0100

Bruno Haible <address@hidden> wrote:
> It's a long time I last looked at the unicodeio module. I'm applying the
> changes below, for better integration with gnulib.
>
>>   unicodeio.c: In function 'fwrite_success_callback':
>>   unicodeio.c:203: warning: ignoring return value of 'fwrite', declared with 
>> attribute warn_unused_result
>>
>> Would you be open to a change that would suppress the above warning?
>
> Sure, yes. print_unicode_char could return EOF upon error on the stream, like
> other stdio functions do.
>
>> One way would be to use the value and make the function return an
>> indication of failure.
>> Alternatively, use ignore_value (from ignore-value.h) to make
>> explicit the desire to ignore the return value.
>
> But what is the reason of the warning, and what is the best approach?
>   - Does the attribute warn_unused_result come from the glibc headers
>     or from a third-party header file?

>From recent glibc headers when compiling with -O and -D_FORTIFY_SOURCE=2

>   - In coreutils, there are plenty of fwrite() calls which drop the
>     return value.

Good point.
It's odd that only the ones from gnulib would evoke a warning.
I tracked it down to the fact that coreutils/src/*.c all include
system.h, which includes unlocked-io.h, which in turn defines all
of those functions, including fwrite, to their *_unlocked equivalents.

>   - 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.

> 2008-11-12  Bruno Haible  <address@hidden>
>
>       * lib/unicodeio.c: Include unistr.h.
>       (utf8_wctomb): Remove function.
>       (unicode_to_mb): Use utf8_uctomb instead of utf8_wctomb.

This causes a link error in coreutils, due to the absence of a utf8_uctomb
definition.  Is it defined in some file you have yet to commit?
Or is that supposed to be some other symbol?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]