summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsobrado <sobrado@openbsd.org>2014-02-01 23:34:49 +0000
committersobrado <sobrado@openbsd.org>2014-02-01 23:34:49 +0000
commitefe832d274de7267afedb525427ae98c76d84423 (patch)
tree289112f9eb462d88f79fe739858970e1e2a09b91
parentremove -e sed option where only one command is used (diff)
downloadwireguard-openbsd-efe832d274de7267afedb525427ae98c76d84423.tar.xz
wireguard-openbsd-efe832d274de7267afedb525427ae98c76d84423.zip
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@
-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;