Subject: Re: bug#11631: closed (Re: bug#11631: Head command does not position file pointer correctly for negative line count)

From: Jim Meyering <[email-masked]>
Date: Wed, 06 Jun 2012 15:01:25 +0200

Jim Meyering wrote:
> Anoop Sharma wrote:
>> 1. The comment in code - "Don't bother testing for failure for such a
>> small amount. Any failure will be detected upon close." may be
>> re-looked too, since we are now lseeking after it.
>>
>> What if we change plain fwrite to:
>>       if (fwrite (buffer, 1, n + 1, stdout) < (n + 1))
>>             error (EXIT_FAILURE, errno, _("write error"));
...
> Regarding #1, thanks for the suggestion.  You're right.

Actually, the existing code is fine.
I'm glad I didn't push that change in your name.
It's not that it would introduce a bug or anything,
but the rationale was incorrect:

The fwrite affects only the output stream, stdout,
while the lseek operates on the input file descriptor,
so they are independent, and the comment is still valid.
The only possible overlap is errno, but if lseek fails,
we now exit immediately, so whether close_stdout has
an errno or not is irrelevant.