summaryrefslogtreecommitdiff
path: root/usr.bin/cut
diff options
context:
space:
mode:
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;