From fcd08ee02a660e7c3013b073e7122be5094e8d47 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 8 Jun 2016 23:26:48 -0400 Subject: Implement -fprint and -fprint0. --- eval.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 828a33f..c3e29d2 100644 --- a/eval.c +++ b/eval.c @@ -626,11 +626,21 @@ bool eval_print(const struct expr *expr, struct eval_state *state) { } /** - * -print0 action. + * -fprint action. + */ +bool eval_fprint(const struct expr *expr, struct eval_state *state) { + const char *path = state->ftwbuf->path; + fputs(path, expr->file); + fputc('\n', expr->file); + return true; +} + +/** + * -f?print0 action. */ bool eval_print0(const struct expr *expr, struct eval_state *state) { const char *path = state->ftwbuf->path; - fwrite(path, 1, strlen(path) + 1, stdout); + fwrite(path, 1, strlen(path) + 1, expr->file); return true; } @@ -857,7 +867,7 @@ static enum bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) { /** * Infer the number of open file descriptors we're allowed to have. */ -static int infer_fdlimit() { +static int infer_fdlimit(const struct cmdline *cmdline) { int ret = 4096; struct rlimit rl; @@ -867,8 +877,8 @@ static int infer_fdlimit() { } } - // std{in,out,err} - int nopen = 3; + // 3 for std{in,out,err} + int nopen = 3 + cmdline->nopen_files; // Check /dev/fd for the current number of open fds, if possible (we may // have inherited more than just the standard ones) @@ -914,7 +924,7 @@ int eval_cmdline(const struct cmdline *cmdline) { return 0; } - int nopenfd = infer_fdlimit(); + int nopenfd = infer_fdlimit(cmdline); struct callback_args args = { .cmdline = cmdline, -- cgit v1.2.3