summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-04-19 14:50:48 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-04-19 15:50:45 -0400
commit48d91c62cd27c15fe0e928abf6d023d17e9c41f7 (patch)
treea6dd2dfb7acddb2e45bdbdddf4fced3ae0155e15 /src
parent111cc3af4b6132fda47d18683a04985ca7c571c2 (diff)
downloadbfs-48d91c62cd27c15fe0e928abf6d023d17e9c41f7.tar.xz
config: Check for struct stat::st_{a,c,m,birth}{tim,timespec}
Diffstat (limited to 'src')
-rw-r--r--src/bfstd.h20
-rw-r--r--src/stat.c11
2 files changed, 22 insertions, 9 deletions
diff --git a/src/bfstd.h b/src/bfstd.h
index 42f5d5b..f91e380 100644
--- a/src/bfstd.h
+++ b/src/bfstd.h
@@ -283,11 +283,21 @@ int xminor(dev_t dev);
// #include <sys/stat.h>
-#if __APPLE__
-# define st_atim st_atimespec
-# define st_ctim st_ctimespec
-# define st_mtim st_mtimespec
-# define st_birthtim st_birthtimespec
+/**
+ * Get the access/change/modification time from a struct stat.
+ */
+#if BFS_HAS_ST_ACMTIM
+# define ST_ATIM(sb) (sb).st_atim
+# define ST_CTIM(sb) (sb).st_ctim
+# define ST_MTIM(sb) (sb).st_mtim
+#elif BFS_HAS_ST_ACMTIMESPEC
+# define ST_ATIM(sb) (sb).st_atimespec
+# define ST_CTIM(sb) (sb).st_ctimespec
+# define ST_MTIM(sb) (sb).st_mtimespec
+#else
+# define ST_ATIM(sb) ((struct timespec) { .tv_sec = (sb).st_atime })
+# define ST_CTIM(sb) ((struct timespec) { .tv_sec = (sb).st_ctime })
+# define ST_MTIM(sb) ((struct timespec) { .tv_sec = (sb).st_mtime })
#endif
// #include <sys/wait.h>
diff --git a/src/stat.c b/src/stat.c
index e525f24..a32dbaa 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -104,18 +104,21 @@ void bfs_stat_convert(struct bfs_stat *dest, const struct stat *src) {
dest->mask |= BFS_STAT_ATTRS;
#endif
- dest->atime = src->st_atim;
+ dest->atime = ST_ATIM(*src);
dest->mask |= BFS_STAT_ATIME;
- dest->ctime = src->st_ctim;
+ dest->ctime = ST_CTIM(*src);
dest->mask |= BFS_STAT_CTIME;
- dest->mtime = src->st_mtim;
+ dest->mtime = ST_MTIM(*src);
dest->mask |= BFS_STAT_MTIME;
-#if __APPLE__ || __FreeBSD__ || __NetBSD__
+#if BFS_HAS_ST_BIRTHTIM
dest->btime = src->st_birthtim;
dest->mask |= BFS_STAT_BTIME;
+#elif BFS_HAS_ST_BIRTHTIMESPEC
+ dest->btime = src->st_birthtimespec;
+ dest->mask |= BFS_STAT_BTIME;
#endif
}