From b2e69d3f76270fc4051801cac923307514184055 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 20 Dec 2018 17:06:27 -0500 Subject: stat: Unify bfs_stat_time() implementations --- eval.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'eval.c') 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; } /** -- cgit v1.2.3