[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Test failure in tac (coreutils-5.92) on Solaris
From: |
Peter Fales |
Subject: |
Re: Test failure in tac (coreutils-5.92) on Solaris |
Date: |
Mon, 24 Oct 2005 13:21:22 -0500 |
User-agent: |
Mutt/1.4.2.1i |
Thanks for the quick patch! It works for me.
For the record, this patch was also needed on HP/UX, Mac OS X, and Irix.
--
Peter Fales Lucent Technologies, Room 1C-436
N9IYJ 2000 Lucent Ln, PO Box 3033
internet: address@hidden Naperville, IL 60566-7033
work: (630) 979-8031
On Mon, Oct 24, 2005 at 06:07:14PM +0200, Jim Meyering wrote:
> Peter Fales <address@hidden> wrote:
> > On Solaris, tac is failing when reading from stdin and stdin is a terminal.
> > (it works on Linux) E.g. a command like this works:
> >
> > $ echo 'a\nb' | tac
> > b
> > a
> >
> > But simply running tac from the command line results in getting a shell
> > prompt back (no chance to type anything):
> >
> > $ tac
> > $
> >
> >
> > The problem seems to be around line 548 in tac.c
> >
> > 548 file_size = lseek (fd, (off_t) 0, SEEK_END);
> > 549
> > 550 ok = (0 <= file_size
> > 551 ? tac_seekable (fd, filename)
> > 552 : tac_nonseekable (fd, filename));
> >
> > On linux lseeking on stdin returns -1, resulting in a call to
> > tac_nonseekable. But, on Solaris, lseek returns 0.
>
> Thanks for the detailed report.
> Here's a patch:
>
> 2005-10-24 Jim Meyering <address@hidden>
>
> * src/tac.c (tac_file): When determining whether a file is seekable,
> also test whether it is a tty. Using only the lseek-based test would
> give a false positive on Solaris. Reported by Peter Fales.
>
> Index: src/tac.c
> ===================================================================
> RCS file: /fetish/cu/src/tac.c,v
> retrieving revision 1.125
> diff -u -p -r1.125 tac.c
> --- src/tac.c 9 Sep 2005 21:11:36 -0000 1.125
> +++ src/tac.c 24 Oct 2005 16:01:53 -0000
> @@ -547,9 +547,9 @@ tac_file (const char *filename)
>
> file_size = lseek (fd, (off_t) 0, SEEK_END);
>
> - ok = (0 <= file_size
> - ? tac_seekable (fd, filename)
> - : tac_nonseekable (fd, filename));
> + ok = (file_size < 0 || isatty (fd)
> + ? tac_nonseekable (fd, filename)
> + : tac_seekable (fd, filename));
>
> if (!is_stdin && close (fd) != 0)
> {