summaryrefslogtreecommitdiffstats
path: root/src/stat.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-01-16 11:06:28 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-01-18 20:07:40 -0500
commit3fa8f1a22ad120322bbc68823ca9759d8939b131 (patch)
tree6c26b40f43ef7987582de08980f705414ef7abfb /src/stat.h
parent40e195c1bd60737964bb2b8ab25780a02003f8e1 (diff)
downloadbfs-3fa8f1a22ad120322bbc68823ca9759d8939b131.tar.xz
stat: Expose bfs_stat{,x}_convert()
Diffstat (limited to 'src/stat.h')
-rw-r--r--src/stat.h41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/stat.h b/src/stat.h
index e08dd4d..68a5c13 100644
--- a/src/stat.h
+++ b/src/stat.h
@@ -13,13 +13,34 @@
#define BFS_STAT_H
#include "config.h"
+#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
+#if defined(STATX_BASIC_STATS) && (!__ANDROID__ || __ANDROID_API__ >= 30)
+# define BFS_HAS_LIBC_STATX true
+#elif __linux__
+# include <linux/stat.h>
+#endif
+
+#ifndef BFS_USE_STATX
+# ifdef STATX_BASIC_STATS
+# define BFS_USE_STATX true
+# endif
+#endif
+
#if BFS_USE_SYS_PARAM_H
# include <sys/param.h>
#endif
+#ifdef DEV_BSIZE
+# define BFS_STAT_BLKSIZE DEV_BSIZE
+#elif defined(S_BLKSIZE)
+# define BFS_STAT_BLKSIZE S_BLKSIZE
+#else
+# define BFS_STAT_BLKSIZE 512
+#endif
+
/**
* bfs_stat field bitmask.
*/
@@ -60,14 +81,6 @@ enum bfs_stat_flags {
BFS_STAT_NOSYNC = 1 << 2,
};
-#ifdef DEV_BSIZE
-# define BFS_STAT_BLKSIZE DEV_BSIZE
-#elif defined(S_BLKSIZE)
-# define BFS_STAT_BLKSIZE S_BLKSIZE
-#else
-# define BFS_STAT_BLKSIZE 512
-#endif
-
/**
* Facade over struct stat.
*/
@@ -125,6 +138,18 @@ struct bfs_stat {
int bfs_stat(int at_fd, const char *at_path, enum bfs_stat_flags flags, struct bfs_stat *buf);
/**
+ * Convert struct stat to struct bfs_stat.
+ */
+void bfs_stat_convert(struct bfs_stat *dest, const struct stat *src);
+
+#if BFS_USE_STATX
+/**
+ * Convert struct statx to struct bfs_stat.
+ */
+int bfs_statx_convert(struct bfs_stat *dest, const struct statx *src);
+#endif
+
+/**
* Get a particular time field from a bfs_stat() buffer.
*/
const struct timespec *bfs_stat_time(const struct bfs_stat *buf, enum bfs_stat_field field);