GNU bug report logs -
#11631
Head command does not position file pointer correctly for negative line count
Previous Next
Full log
Message #43 received at 11631 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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 eblake <at> redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 13 years and 46 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.