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: Anoop Sharma
Subject: bug#11631: closed (Re: bug#11631: Head command does not position file pointer correctly for negative line count)
Date: Wed, 6 Jun 2012 09:30:11 +0530

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"));

2. Maybe using lseek with SEEK_CUR in place of SEEK_SET would reflect
logic better.

With Thanks for quick responses,
Anoop

On Wed, Jun 6, 2012 at 2:08 AM, GNU bug Tracking System
<address@hidden> wrote:
>
> Your bug report
>
> #11631: Head command does not position file pointer correctly for negative 
> line count
>
> which was filed against the coreutils package, has been closed.
>
> The explanation is attached below, along with your original report.
> If you require more details, please reply to address@hidden
>
> --
> 11631: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11631
> GNU Bug Tracking System
> Contact address@hidden with problems
>
>
> ---------- Forwarded message ----------
> From: Jim Meyering <address@hidden>
> To: Pádraig Brady <address@hidden>
> Cc:address@hidden
> Date: Tue, 05 Jun 2012 22:35:13 +0200
> Subject: Re: bug#11631: Head command does not position file pointer correctly 
> for negative line count
> Jim Meyering wrote:
> > Thanks, and thanks for the review.  Pushed.
>
> And with this message, I've closed the issue.
>
>
>
> ---------- Forwarded message ----------
> From: Anoop Sharma <address@hidden>
> To:address@hidden
> Cc:
> Date: Tue, 5 Jun 2012 15:07:19 +0530
> Subject: Head command does not position file pointer correctly for negative 
> line count
> Head command does not position file pointer correctly for negative line 
> count. Here is a demonstration of the problem.
>
> Step 1 - Create a file with 10 lines in it.
> $ yes "ABC" | head -c 40 >ip.txt
> $
>
> Step 2 - If head behaves correctly, then 2 lines should get printed after 
> "------------" but nothing gets printed!
> $ (head -n -2; echo "------------------------"; cat) <ip.txt
> ABC
> ABC
> ABC
> ABC
> ABC
> ABC
> ABC
> ABC
> ------------------------
> $
>
> Step 3 - Another try fails. If head behaves correctly, then 8 lines should 
> get printed after "------------" but nothing gets printed!
> $ (head -n -8; echo "------------------------"; cat) <ip.txt
> ABC
> ABC
> ------------------------
> $
>
>
>
> /*****************************************************************************************************************************/
> Possible cause of the defect -> Following snippet is copied from head.c 
> (Function - elide_tail_lines_seekable ). Perhaps, there should be a lseek 
> after fwrite there...:
>
>               /* 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);
> /*****************************************************************************************************************************/
>
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]