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 --- stat.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'stat.c') diff --git a/stat.c b/stat.c index 8ce13e9..c567873 100644 --- a/stat.c +++ b/stat.c @@ -16,6 +16,7 @@ #include "stat.h" #include "util.h" +#include #include #include #include @@ -151,7 +152,7 @@ static int bfs_statx_impl(int at_fd, const char *at_path, int at_flags, enum bfs // Callers shouldn't have to check anything except the times const int guaranteed = STATX_BASIC_STATS ^ (STATX_ATIME | STATX_CTIME | STATX_MTIME); if ((xbuf.stx_mask & guaranteed) != guaranteed) { - errno = EINVAL; + errno = ENODATA; return -1; } @@ -268,3 +269,25 @@ int bfs_fstat(int fd, struct bfs_stat *buf) { } return ret; } + +const struct timespec *bfs_stat_time(const struct bfs_stat *buf, enum bfs_stat_field field) { + if (!(buf->mask & field)) { + errno = ENODATA; + return NULL; + } + + switch (field) { + case BFS_STAT_ATIME: + return &buf->atime; + case BFS_STAT_BTIME: + return &buf->btime; + case BFS_STAT_CTIME: + return &buf->ctime; + case BFS_STAT_MTIME: + return &buf->mtime; + default: + assert(false); + errno = EINVAL; + return NULL; + } +} -- cgit v1.2.3