Subject: bin/32931: cat(1) does not clear the EOF indicator for stdin in cooked mode
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Johan Veenhuizen <veenhuizen@users.sourceforge.net>
List: netbsd-bugs
Date: 02/26/2006 01:35:00
>Number: 32931
>Category: bin
>Synopsis: cat(1) does not clear the EOF indicator for stdin in cooked mode
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Feb 26 01:35:00 +0000 2006
>Originator: Johan Veenhuizen
>Release: NetBSD 3.0
>Organization:
>Environment:
System: NetBSD carola.zapto.org 3.0 NetBSD 3.0 (CAROLA) #0: Tue Feb 21 15:27:43 CET 2006 jpv@carola.zapto.org:/usr/src/sys/arch/i386/compile/CAROLA i386
Architecture: i386
Machine: i386
>Description:
cat(1) does not clear the EOF indicator for standard input
when operating in "cooked" mode (i.e. when one of the flags
-benstv are given). If the dash representing standard input
appears multiple times in the file list under these flags,
standard input will only be read once.
>How-To-Repeat:
The following sample session reads standard input twice
before exiting:
$ cat - -
hello
hello
^D
goodbye
goodbye
^D
$ _
If we add the -s flag (squeeze multiple adjacent empty lines),
standard input will only be read once.
$ cat -s - -
hello
hello
^D
$ _
>Fix:
Apply the following patch, which clears the EOF indicator
after each pass over standard input.
Index: src/bin/cat/cat.c
===================================================================
RCS file: /cvsroot/src/bin/cat/cat.c,v
retrieving revision 1.43
diff -u -r1.43 cat.c
--- src/bin/cat/cat.c 4 Jan 2004 03:31:28 -0000 1.43
+++ src/bin/cat/cat.c 26 Feb 2006 01:00:07 -0000
@@ -160,6 +160,8 @@
cook_buf(fp);
if (fp != stdin)
(void)fclose(fp);
+ else
+ clearerr(fp);
} while (*argv);
}
>Unformatted: