On 06/06/2012 02:02 AM, Jim Meyering wrote:

> +++ b/src/head.c
> @@ -663,10 +663,9 @@ elide_tail_lines_seekable (const char *pretty_filename, 
> int fd,
>                  }
> 
>                /* Output the initial portion of the buffer
> -                 in which we found the desired newline byte.
> -                 Don't bother testing for failure for such a small amount.
> -                 Any failure will be detected upon close.  */
> -              fwrite (buffer, 1, n + 1, stdout);
> +                 in which we found the desired newline byte.  */
> +              if (fwrite (buffer, 1, n + 1, stdout) < n + 1)
> +                error (EXIT_FAILURE, errno, _("write error"));

Is testing for fwrite() sufficient?  Shouldn't you actually be testing
for fflush() errors, since fwrite() buffers the output and might not
actually encounter an error until it flushes?  Or even on NFS, where
fflush() may succeed but fclose() fails?  In other words, our atexit()
handler for detecting fclose() failure will already catch things; we may
still be in a situation where fwrite() succeeds, we then do lseek(), but
fclose() fails, in spite of our efforts.  I don't see how this patch
improves anything, other than earlier error reporting.

-- 
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to