summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-06-08 23:26:48 -0400
committerTavian Barnes <tavianator@tavianator.com>2016-06-08 23:26:48 -0400
commitfcd08ee02a660e7c3013b073e7122be5094e8d47 (patch)
tree915bb5c2e1d0ed34d1a45c091f3b8f8972413653 /eval.c
parent593e2135a98b66999f3143c70dd5169701972906 (diff)
downloadbfs-fcd08ee02a660e7c3013b073e7122be5094e8d47.tar.xz
Implement -fprint and -fprint0.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c22
1 files changed, 16 insertions, 6 deletions
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,