summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-11-17 21:05:42 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2016-11-19 01:18:31 -0800
commitfc6fce9a16bc52aca11cd8f1ad2632943fe94201 (patch)
treea32ad60b845c616ea4756147f75adbf5958f1b68 /src
parent2a45b2fbe2ca6d2d6c161d1593511b92d9e4640e (diff)
downloadgrep-fc6fce9a16bc52aca11cd8f1ad2632943fe94201.tar.gz
grep: treat -f /dev/null like -m0
* NEWS: Document this. * src/grep.c (main): With -f /dev/null, don't bother to read the input. This is what FreeBSD grep does. * tests/Makefile.am (TESTS): Add skip-read. * tests/skip-read: New file.
Diffstat (limited to 'src')
-rw-r--r--src/grep.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/grep.c b/src/grep.c
index fe56e9cc..317a0d5d 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2866,7 +2866,10 @@ main (int argc, char **argv)
if (O_BINARY && !isatty (STDOUT_FILENO))
set_binary_mode (STDOUT_FILENO, O_BINARY);
- if (max_count == 0)
+ /* If it is easy to see that matching cannot succeed (e.g., 'grep -f
+ /dev/null'), fail without reading the input. */
+ if (max_count == 0
+ || (keycc == 0 && out_invert && !match_lines && !match_words))
return EXIT_FAILURE;
/* Prefer sysconf for page size, as getpagesize typically returns int. */