GNU bug report logs - #11631
Head command does not position file pointer correctly for negative line count

Previous Next

Package: coreutils;

Reported by: Anoop Sharma <sendtoanoop <at> gmail.com>

Date: Tue, 5 Jun 2012 09:41:01 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


Message #46 received at 11631 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Anoop Sharma <sendtoanoop <at> gmail.com>
Cc: 11631 <at> debbugs.gnu.org
Subject: Re: bug#11631: closed (Re: bug#11631: Head command does not position
	file pointer correctly for negative line count)
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.




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.