summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-02-12 15:26:04 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-02-12 15:26:04 -0500
commit5eba5cb9215edff62e2bd7070bb690913cdae7c7 (patch)
treef5cc9f093acf51eb4ec06f946b067014e3542497 /eval.c
parent3d167f2a35fc94ed7521909b8c7ef126aaa4bed6 (diff)
downloadbfs-5eba5cb9215edff62e2bd7070bb690913cdae7c7.tar.xz
Consolidate some error reporting logic.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/eval.c b/eval.c
index a045d39..f08bab5 100644
--- a/eval.c
+++ b/eval.c
@@ -36,6 +36,14 @@ struct eval_state {
};
/**
+ * Report an error that occurs during evaluation.
+ */
+static void eval_error(struct eval_state *state) {
+ print_error(state->cmdline->colors, state->ftwbuf->path, errno);
+ state->ret = -1;
+}
+
+/**
* Perform a stat() call if necessary.
*/
static const struct stat *fill_statbuf(struct eval_state *state) {
@@ -44,8 +52,7 @@ static const struct stat *fill_statbuf(struct eval_state *state) {
if (fstatat(ftwbuf->at_fd, ftwbuf->at_path, &state->statbuf, AT_SYMLINK_NOFOLLOW) == 0) {
ftwbuf->statbuf = &state->statbuf;
} else {
- state->ret = -1;
- perror("fstatat()");
+ eval_error(state);
}
}
return ftwbuf->statbuf;
@@ -197,7 +204,7 @@ bool eval_delete(const struct expr *expr, struct eval_state *state) {
}
if (unlinkat(ftwbuf->at_fd, ftwbuf->at_path, flag) != 0) {
- print_error(state->cmdline->colors, ftwbuf->path, errno);
+ eval_error(state);
state->action = BFTW_STOP;
}
@@ -214,15 +221,13 @@ bool eval_empty(const struct expr *expr, struct eval_state *state) {
if (ftwbuf->typeflag == BFTW_DIR) {
int dfd = openat(ftwbuf->at_fd, ftwbuf->at_path, O_DIRECTORY);
if (dfd < 0) {
- state->ret = -1;
- perror("openat()");
+ eval_error(state);
goto done;
}
DIR *dir = fdopendir(dfd);
if (!dir) {
- state->ret = -1;
- perror("fdopendir()");
+ eval_error(state);
close(dfd);
goto done;
}