summaryrefslogtreecommitdiffstats
path: root/stat.c
diff options
context:
space:
mode:
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;
+ }
+}