aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/grep.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-08-21 05:38:53 -0500
committerRob Landley <rob@landley.net>2013-08-21 05:38:53 -0500
commite6e685cdb8f6e30607c25dcac5f8dc93d4230c20 (patch)
tree56243cc97e5b272dfeceeb97d2c9c95eebfb80ab /toys/posix/grep.c
parent5f80533836c60a167f69b71624fad5c494057ee2 (diff)
downloadtoybox-e6e685cdb8f6e30607c25dcac5f8dc93d4230c20.tar.gz
Fix bug where exit code was only correct for -q.
Diffstat (limited to 'toys/posix/grep.c')
-rw-r--r--toys/posix/grep.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 7a2ca3a3..4338a552 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -84,7 +84,11 @@ static void do_grep(int fd, char *name)
char *s = 0;
for (seek = TT.e; seek; seek = seek->next) {
- if (!*seek->arg) {
+ if (toys.optflags & FLAG_x) {
+ int i = (toys.optflags & FLAG_i);
+
+ if ((i ? strcasecmp : strcmp)(seek->arg, line)) s = line;
+ } else if (!*seek->arg) {
seek = &fseek;
fseek.arg = s = line;
break;
@@ -127,10 +131,8 @@ static void do_grep(int fd, char *name)
} else if (rc) break;
mmatch++;
- if (toys.optflags & FLAG_q) {
- toys.exitval = 0;
- xexit();
- }
+ toys.exitval = 0;
+ if (toys.optflags & FLAG_q) xexit();
if (toys.optflags & FLAG_l) {
printf("%s\n", name);
free(line);