[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: |
Jim Meyering |
Subject: |
Re: Test failure in tac (coreutils-5.92) on Solaris |
Date: |
Mon, 24 Oct 2005 18:07:14 +0200 |
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)
{