summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-12-20 17:06:27 -0500
committerTavian Barnes <tavianator@tavianator.com>2018-12-20 17:06:27 -0500
commitb2e69d3f76270fc4051801cac923307514184055 (patch)
tree6dbfd40393a437ede929ab1748520a050e593b02 /eval.c
parent5bec8030c77b735147cdf73359bc8f91b19e28fb (diff)
downloadbfs-b2e69d3f76270fc4051801cac923307514184055.tar.xz
stat: Unify bfs_stat_time() implementations
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/eval.c b/eval.c
index 5d71318..f636173 100644
--- a/eval.c
+++ b/eval.c
@@ -214,8 +214,10 @@ bool eval_capable(const struct expr *expr, struct eval_state *state) {
* Get the given timespec field out of a stat buffer.
*/
static const struct timespec *eval_stat_time(const struct bfs_stat *statbuf, enum bfs_stat_field field, const struct eval_state *state) {
- if (!(statbuf->mask & field)) {
- const char *kind = "";
+ const struct timespec *ret = bfs_stat_time(statbuf, field);
+
+ if (!ret) {
+ const char *kind;
switch (field) {
case BFS_STAT_ATIME:
kind = "access";
@@ -231,27 +233,15 @@ static const struct timespec *eval_stat_time(const struct bfs_stat *statbuf, enu
break;
default:
assert(false);
+ kind = "???";
break;
}
- cfprintf(state->cmdline->cerr, "%{er}error: '%s': Couldn't get file %s time.%{rs}\n", state->ftwbuf->path, kind);
+ cfprintf(state->cmdline->cerr, "%{er}error: '%s': Couldn't get file %s time: %s%{rs}\n", state->ftwbuf->path, kind, strerror(errno));
*state->ret = EXIT_FAILURE;
- return NULL;
- }
-
- switch (field) {
- case BFS_STAT_ATIME:
- return &statbuf->atime;
- case BFS_STAT_BTIME:
- return &statbuf->btime;
- case BFS_STAT_CTIME:
- return &statbuf->ctime;
- case BFS_STAT_MTIME:
- return &statbuf->mtime;
- default:
- assert(false);
- return NULL;
}
+
+ return ret;
}
/**