From e6e685cdb8f6e30607c25dcac5f8dc93d4230c20 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 21 Aug 2013 05:38:53 -0500 Subject: Fix bug where exit code was only correct for -q. --- toys/posix/grep.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'toys/posix/grep.c') 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); -- cgit v1.2.3