summaryrefslogtreecommitdiff
path: root/usr.bin/cut
diff options
context:
space:
mode:
authorIgor Sobrado <sobrado@cvs.openbsd.org>2014-02-01 23:34:50 +0000
committerIgor Sobrado <sobrado@cvs.openbsd.org>2014-02-01 23:34:50 +0000
commit20353eeaf61efbd2cb6d969a3494f7a3847f1a30 (patch)
tree25851195b17c092bd7b9f9b564823d51c3409dbb /usr.bin/cut
parent915d9c7bf3a6e6b8164cf372905fd855294d6f9c (diff)
improve POSIX compliance by continuing to process the remaining file
operands after not finding an input file. from the IEEE Std 1003.1-2008 (``POSIX.1'') rationale: "Unlike other utilities, some historical implementations of cut exit after not finding an input file, rather than continuing to process the remaining file operands. This behavior is prohibited by this volume of POSIX.1-2008, where only the exit status is affected by this problem." joint work with jmc@, who identified the compliance issue, and millert@ ok millert@, jmc@
Diffstat (limited to 'usr.bin/cut')
-rw-r--r--usr.bin/cut/cut.111
-rw-r--r--usr.bin/cut/cut.c21
2 files changed, 22 insertions, 10 deletions
diff --git a/usr.bin/cut/cut.1 b/usr.bin/cut/cut.1
index 7d282b84e26..d3bb88add8d 100644
--- a/usr.bin/cut/cut.1
+++ b/usr.bin/cut/cut.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cut.1,v 1.20 2014/02/01 22:47:49 sobrado Exp $
+.\" $OpenBSD: cut.1,v 1.21 2014/02/01 23:34:49 sobrado Exp $
.\" $NetBSD: cut.1,v 1.6 1995/10/02 20:19:26 jtc Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
@@ -59,8 +59,13 @@ utility selects portions of each line (as specified by
.Ar list )
from each
.Ar file
-(or the standard input by default), and writes them to the
-standard output.
+and writes them to the standard output.
+If no
+.Ar file
+arguments are specified, or a file argument is a single dash
+.Pq Sq \- ,
+.Nm
+reads from the standard input.
The items specified by
.Ar list
can be in terms of column position or in terms of fields delimited
diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c
index 9590800b93d..57e820a9dec 100644
--- a/usr.bin/cut/cut.c
+++ b/usr.bin/cut/cut.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cut.c,v 1.16 2013/11/23 17:30:29 deraadt Exp $ */
+/* $OpenBSD: cut.c,v 1.17 2014/02/01 23:34:49 sobrado Exp $ */
/* $NetBSD: cut.c,v 1.9 1995/09/02 05:59:23 jtc Exp $ */
/*
@@ -59,7 +59,7 @@ main(int argc, char *argv[])
{
FILE *fp;
void (*fcn)(FILE *, char *);
- int ch;
+ int ch, eval = 0;
setlocale (LC_ALL, "");
@@ -104,14 +104,21 @@ main(int argc, char *argv[])
if (*argv)
for (; *argv; ++argv) {
- if (!(fp = fopen(*argv, "r")))
- err(1, "%s", *argv);
- fcn(fp, *argv);
- (void)fclose(fp);
+ if (strcmp(*argv, "-") == 0)
+ fcn(stdin, "stdin");
+ else {
+ if ((fp = fopen(*argv, "r"))) {
+ fcn(fp, *argv);
+ (void)fclose(fp);
+ } else {
+ eval = 1;
+ warn("%s", *argv);
+ }
+ }
}
else
fcn(stdin, "stdin");
- exit(0);
+ exit(eval);
}
int autostart, autostop, maxval;