aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-12-09 19:37:48 -0600
committerRob Landley <rob@landley.net>2018-12-09 19:37:48 -0600
commit004ab612d5cb65685b6d7442437f2c98b1a81f52 (patch)
tree31618650239a6832026115c4ab8fc4d81bb38e2a
parent2eb2fdea88b848d07bb8aa7ca22cb624127e440d (diff)
downloadtoybox-004ab612d5cb65685b6d7442437f2c98b1a81f52.tar.gz
More grep.tests: make exit code 2 happen when it should.
-rw-r--r--toys/posix/grep.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 49c69dd0..5daccabc 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -68,7 +68,7 @@ GLOBALS(
struct arg_list *f, *e, *M, *S;
char indelim, outdelim;
- int found;
+ int found, tried;
)
// Emit line with various potential prefixes and delimiter
@@ -92,6 +92,7 @@ static void do_grep(int fd, char *name)
FILE *file;
int bin = 0;
+ TT.tried++;
if (!fd) name = "(standard input)";
// Only run binary file check on lseekable files.
@@ -248,7 +249,7 @@ static void do_grep(int fd, char *name)
}
start += skip;
- if (!(toys.optflags & FLAG_o)) break;
+ if (!FLAG(o)) break;
} while (*start);
offset += len;
@@ -422,5 +423,5 @@ void grep_main(void)
else dirtree_read(*ss, do_grep_r);
}
} else loopfiles_rw(ss, O_RDONLY|WARN_ONLY, 0, do_grep);
- toys.exitval = !TT.found;
+ if (TT.tried == toys.optc || (FLAG(q)&&TT.found)) toys.exitval = !TT.found;
}