bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH 1/3] fprintftime: depend on stdio, not ignore-value


From: Eric Blake
Subject: Re: [PATCH 1/3] fprintftime: depend on stdio, not ignore-value
Date: Fri, 04 Jan 2013 09:44:11 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

On 01/04/2013 09:36 AM, Paul Eggert wrote:
> Instead of putting back that comment about the bug,
> how about fixing the bug?  Something like the following.
> 
> Or perhaps a fix should be put into stdio.in.h so that
> all gnulib programs can assume glibc behavior here,
> for fwrite?  Though this would mean using an extern
> function, something that caused trouble with libvirt...

Having an extern (not inline) replacement rpl_fwrite for platforms that
can fail with ENOMEM seems reasonable, just like we have replacements
for any other function where we want to guarantee glibc semantics.  That
just means adding a fwrite module and coming up with an appropriate .m4
file to determine when to compile the replacement fwrite.c.  Do we even
know of platforms where fwrite will fail on ENOMEM without setting the
error indicator?

> +static void
> +fwrite_asis (FILE *fp, const CHAR_T *src, size_t len)
> +{
> +  /* POSIX and ISO C allow fwrite to fail due to ENOMEM *without*
> +     setting the stream's error indicator.  Work around the problem
> +     by invoking fwrite only on platforms we know are safe.  */
> +#ifdef __GLIBC__
> +  fwrite (src, len, 1, fp);
> +#else
> +  while (len-- > 0)
> +    {
> +      fputc (*src, fp);
> +      ++src;

This feels slow; wouldn't it better to still just call fwrite(), but
check for an error return, and if so, use the fseterr module to
guarantee that the stream error indicator is set?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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