svn commit: r246279 - stable/9/usr.bin/grep

Eitan Adler eadler at FreeBSD.org
Sun Feb 3 03:38:46 UTC 2013


Author: eadler
Date: Sun Feb  3 03:38:44 2013
New Revision: 246279
URL: http://svnweb.freebsd.org/changeset/base/246279

Log:
  MFC r244493:
  Make bsdgrep behave as gnugrep and as documented: -m should only stop
  	reading the specific file, not any file.
  
  Approved by:	cperciva (mentor, implicit)

Modified:
  stable/9/usr.bin/grep/grep.c
  stable/9/usr.bin/grep/grep.h
  stable/9/usr.bin/grep/util.c
Directory Properties:
  stable/9/usr.bin/grep/   (props changed)

Modified: stable/9/usr.bin/grep/grep.c
==============================================================================
--- stable/9/usr.bin/grep/grep.c	Sun Feb  3 01:54:25 2013	(r246278)
+++ stable/9/usr.bin/grep/grep.c	Sun Feb  3 03:38:44 2013	(r246279)
@@ -107,6 +107,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) */
@@ -529,7 +530,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);

Modified: stable/9/usr.bin/grep/grep.h
==============================================================================
--- stable/9/usr.bin/grep/grep.h	Sun Feb  3 01:54:25 2013	(r246278)
+++ stable/9/usr.bin/grep/grep.h	Sun Feb  3 03:38:44 2013	(r246279)
@@ -115,6 +115,7 @@ extern bool	 Eflag, Fflag, Gflag, Hflag,
 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;

Modified: stable/9/usr.bin/grep/util.c
==============================================================================
--- stable/9/usr.bin/grep/util.c	Sun Feb  3 01:54:25 2013	(r246278)
+++ stable/9/usr.bin/grep/util.c	Sun Feb  3 03:38:44 2013	(r246279)
@@ -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);


More information about the svn-src-stable-9 mailing list