aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-05-08 03:53:46 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-05-08 03:53:46 +0000
commit24a656c2914ab81bda4e535248bdee2ee6e48ceb (patch)
treee608929fb29daa0cd6b9361f30bb6171ef0931b7 /usr.bin
parent10d20c84ed8ac35523a3a20d72a91fb505df2192 (diff)
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/grep/grep.19
-rw-r--r--usr.bin/grep/grep.c7
2 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1
index 1cc72ea239e1..1aa72155a57d 100644
--- a/usr.bin/grep/grep.1
+++ b/usr.bin/grep/grep.1
@@ -30,7 +30,7 @@
.\"
.\" @(#)grep.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd April 25, 2018
+.Dd May 7, 2018
.Dt GREP 1
.Os
.Sh NAME
@@ -404,6 +404,13 @@ and block buffered otherwise.
.El
.Pp
If no file arguments are specified, the standard input is used.
+Additionally,
+.Dq -
+may be used in place of a file name, anywhere that a file name is accepted, to
+read from standard input.
+This includes both
+.Fl f
+and file arguments.
.Sh EXIT STATUS
The
.Nm grep
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index 827c6b987a0f..3d22b3fb1259 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -307,7 +307,9 @@ read_patterns(const char *fn)
size_t len;
ssize_t rlen;
- if ((f = fopen(fn, "r")) == NULL)
+ if (strcmp(fn, "-") == 0)
+ f = stdin;
+ else if ((f = fopen(fn, "r")) == NULL)
err(2, "%s", fn);
if ((fstat(fileno(f), &st) == -1) || (S_ISDIR(st.st_mode))) {
fclose(f);
@@ -324,7 +326,8 @@ read_patterns(const char *fn)
free(line);
if (ferror(f))
err(2, "%s", fn);
- fclose(f);
+ if (strcmp(fn, "-") != 0)
+ fclose(f);
}
static inline const char *