diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2018-12-20 17:06:27 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2018-12-20 17:06:27 -0500 |
commit | b2e69d3f76270fc4051801cac923307514184055 (patch) | |
tree | 6dbfd40393a437ede929ab1748520a050e593b02 /stat.c | |
parent | 5bec8030c77b735147cdf73359bc8f91b19e28fb (diff) | |
download | bfs-b2e69d3f76270fc4051801cac923307514184055.tar.xz |
stat: Unify bfs_stat_time() implementations
Diffstat (limited to 'stat.c')
-rw-r--r-- | stat.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -16,6 +16,7 @@ #include "stat.h" #include "util.h" +#include <assert.h> #include <errno.h> #include <fcntl.h> #include <stdbool.h> @@ -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; + } +} |