Subject: bin/33995: /usr/bin/cut is not conformant to SUSv3
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <cheusov@tut.by>
List: netbsd-bugs
Date: 07/13/2006 15:40:00
>Number:         33995
>Category:       bin
>Synopsis:       /usr/bin/cut: conformance to SUSv3
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 13 15:40:00 +0000 2006
>Originator:     cheusov@tut.by
>Release:        NetBSD 3.0_STABLE
>Organization:
Best regards, Aleksey Cheusov.
>Environment:
System: NetBSD chen.chizhovka.net 3.0_STABLE NetBSD 3.0_STABLE (GENERIC) #2: Sun Mar 12 12:49:58 GMT 2006 cheusov@chen:/usr/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
SUSv3 says that '-' as a filename should be treated by 'cut' utility
as stdin
>How-To-Repeat:
echo '1:2' | cut -f 1 -d : -
>Fix:
Index: cut.c
===================================================================
RCS file: /cvsroot/src/usr.bin/cut/cut.c,v
retrieving revision 1.20
diff -u -r1.20 cut.c
--- cut.c       25 Apr 2006 19:34:42 -0000      1.20
+++ cut.c       13 Jul 2006 15:30:08 -0000
@@ -117,10 +117,14 @@
 
        if (*argv)
                for (; *argv; ++argv) {
-                       if (!(fp = fopen(*argv, "r")))
-                               err(1, "%s", *argv);
-                       fcn(fp, *argv);
-                       (void)fclose(fp);
+                       if (!strcmp (*argv, "-")) {
+                               fcn(stdin, "stdin");
+                       }else{
+                               if (!(fp = fopen(*argv, "r")))
+                                       err(1, "%s", *argv);
+                               fcn(fp, *argv);
+                               (void)fclose(fp);
+                       }
                }
        else
                fcn(stdin, "stdin");