summaryrefslogtreecommitdiffstats
path: root/printf.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 /printf.c
parent5bec8030c77b735147cdf73359bc8f91b19e28fb (diff)
downloadbfs-b2e69d3f76270fc4051801cac923307514184055.tar.xz
stat: Unify bfs_stat_time() implementations
Diffstat (limited to 'printf.c')
-rw-r--r--printf.c28
1 files changed, 2 insertions, 26 deletions
diff --git a/printf.c b/printf.c
index 1da0de7..4fc2dfb 100644
--- a/printf.c
+++ b/printf.c
@@ -76,37 +76,13 @@ static int bfs_printf_flush(FILE *file, const struct bfs_printf_directive *direc
assert(ret >= 0 && ret < sizeof(buf)); \
(void)ret
-/**
- * Get a particular time field from a struct bfs_stat.
- */
-static const struct timespec *get_time_field(const struct bfs_stat *statbuf, enum bfs_stat_field stat_field) {
- if (!(statbuf->mask & stat_field)) {
- errno = ENOTSUP;
- return NULL;
- }
-
- switch (stat_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;
- }
-}
-
/** %a, %c, %t: ctime() */
static int bfs_printf_ctime(FILE *file, const struct bfs_printf_directive *directive, const struct BFTW *ftwbuf) {
// Not using ctime() itself because GNU find adds nanoseconds
static const char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
- const struct timespec *ts = get_time_field(ftwbuf->statbuf, directive->stat_field);
+ const struct timespec *ts = bfs_stat_time(ftwbuf->statbuf, directive->stat_field);
if (!ts) {
return -1;
}
@@ -131,7 +107,7 @@ static int bfs_printf_ctime(FILE *file, const struct bfs_printf_directive *direc
/** %A, %B/%W, %C, %T: strftime() */
static int bfs_printf_strftime(FILE *file, const struct bfs_printf_directive *directive, const struct BFTW *ftwbuf) {
- const struct timespec *ts = get_time_field(ftwbuf->statbuf, directive->stat_field);
+ const struct timespec *ts = bfs_stat_time(ftwbuf->statbuf, directive->stat_field);
if (!ts) {
return -1;
}