bug-coreutils
[Top][All Lists]
Advanced

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

bug#11631: closed (Re: bug#11631: Head command does not position file po


From: Eric Blake
Subject: bug#11631: closed (Re: bug#11631: Head command does not position file pointer correctly for negative line count)
Date: Wed, 06 Jun 2012 05:52:23 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

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   address@hidden    +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]