aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-08-06 15:25:53 +0000
committerMatt Kraai <kraai@debian.org>2000-08-06 15:25:53 +0000
commitdeb95f69b6afab4b9e81cb8b2d63ba98469d1622 (patch)
tree742ec804070ae3e9c88f7a6878bf88ba196b328c /findutils/grep.c
parent46ade979839e6ec400d4b6f2c5bbd209b8940738 (diff)
downloadbusybox-w32-deb95f69b6afab4b9e81cb8b2d63ba98469d1622.tar.gz
busybox-w32-deb95f69b6afab4b9e81cb8b2d63ba98469d1622.tar.bz2
busybox-w32-deb95f69b6afab4b9e81cb8b2d63ba98469d1622.zip
Exit with the appropriate value when grepping multiple files.
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 6161ba766..3ee409c64 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -42,7 +42,7 @@ static int suppress_err_msgs = 0;
42 42
43/* globals */ 43/* globals */
44static regex_t regex; /* storage space for compiled regular expression */ 44static regex_t regex; /* storage space for compiled regular expression */
45static int nmatches = 0; /* keeps track of the number of matches */ 45static int matched; /* keeps track of whether we ever matched */
46static char *cur_file = NULL; /* the current file we are reading */ 46static char *cur_file = NULL; /* the current file we are reading */
47 47
48 48
@@ -64,6 +64,7 @@ static void grep_file(FILE *file)
64 char *line = NULL; 64 char *line = NULL;
65 int ret; 65 int ret;
66 int linenum = 0; 66 int linenum = 0;
67 int nmatches = 0;
67 68
68 while ((line = get_line_from_file(file)) != NULL) { 69 while ((line = get_line_from_file(file)) != NULL) {
69 linenum++; 70 linenum++;
@@ -96,8 +97,9 @@ static void grep_file(FILE *file)
96 printf("%i\n", nmatches); 97 printf("%i\n", nmatches);
97 } 98 }
98 99
99 /* reset number of matches found to zero */ 100 /* record if we matched */
100 nmatches = 0; 101 if (nmatches != 0)
102 matched = 1;
101} 103}
102 104
103extern int grep_main(int argc, char **argv) 105extern int grep_main(int argc, char **argv)
@@ -176,7 +178,7 @@ extern int grep_main(int argc, char **argv)
176 178
177 regfree(&regex); 179 regfree(&regex);
178 180
179 if (nmatches == 0) 181 if (!matched)
180 return 1; 182 return 1;
181 183
182 return 0; 184 return 0;