summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep
diff options
context:
space:
mode:
authoreadler <eadler@FreeBSD.org>2012-12-20 17:38:14 +0000
committereadler <eadler@FreeBSD.org>2012-12-20 17:38:14 +0000
commit7e7d24dbbf4960d0b440589631a159251f272a87 (patch)
tree7e80a178845ab1ecc1c7f96d387b987540d59abf /usr.bin/grep
parent47c432b02105d7a7e328df3dfa437fb150790d9e (diff)
downloadFreeBSD-src-7e7d24dbbf4960d0b440589631a159251f272a87.zip
FreeBSD-src-7e7d24dbbf4960d0b440589631a159251f272a87.tar.gz
Make bsdgrep behave as gnugrep and as documented: -m should only stop
reading the specific file, not any file. Tested by: frogs (irc) Reviewed by: gabor Approved by: cperciva (implicit) MFC after: 1 week
Diffstat (limited to 'usr.bin/grep')
-rw-r--r--usr.bin/grep/grep.c3
-rw-r--r--usr.bin/grep/grep.h1
-rw-r--r--usr.bin/grep/util.c3
3 files changed, 4 insertions, 3 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index 43d9334..7c69d5d 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -108,6 +108,7 @@ bool iflag; /* -i: ignore case */
bool lflag; /* -l: only show names of files with matches */
bool mflag; /* -m x: stop reading the files after x matches */
long long mcount; /* count for -m */
+long long mlimit; /* requested value for -m */
bool nflag; /* -n: show line numbers in front of matching lines */
bool oflag; /* -o: print only matching part */
bool qflag; /* -q: quiet mode (don't output anything) */
@@ -524,7 +525,7 @@ main(int argc, char *argv[])
case 'm':
mflag = true;
errno = 0;
- mcount = strtoll(optarg, &ep, 10);
+ mlimit = mcount = strtoll(optarg, &ep, 10);
if (((errno == ERANGE) && (mcount == LLONG_MAX)) ||
((errno == EINVAL) && (mcount == 0)))
err(2, NULL);
diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h
index 2a8f425..4ee348e 100644
--- a/usr.bin/grep/grep.h
+++ b/usr.bin/grep/grep.h
@@ -115,6 +115,7 @@ extern bool Eflag, Fflag, Gflag, Hflag, Lflag,
extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
extern unsigned long long Aflag, Bflag;
extern long long mcount;
+extern long long mlimit;
extern char *label;
extern const char *color;
extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 4fb1240..0a3706f 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -176,8 +176,7 @@ procfile(const char *fn)
mode_t s;
int c, t;
- if (mflag && (mcount <= 0))
- return (0);
+ mcount = mlimit;
if (strcmp(fn, "-") == 0) {
fn = label != NULL ? label : getstr(1);
OpenPOWER on IntegriCloud