summaryrefslogtreecommitdiffstats
path: root/stat.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 /stat.c
parent5bec8030c77b735147cdf73359bc8f91b19e28fb (diff)
downloadbfs-b2e69d3f76270fc4051801cac923307514184055.tar.xz
stat: Unify bfs_stat_time() implementations
Diffstat (limited to 'stat.c')
-rw-r--r--stat.c25
1 files changed, 24 insertions, 1 deletions
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 <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;
+ }
+}