From 3fa8f1a22ad120322bbc68823ca9759d8939b131 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 16 Jan 2024 11:06:28 -0500 Subject: stat: Expose bfs_stat{,x}_convert() --- src/stat.h | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'src/stat.h') 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 #include #include +#if defined(STATX_BASIC_STATS) && (!__ANDROID__ || __ANDROID_API__ >= 30) +# define BFS_HAS_LIBC_STATX true +#elif __linux__ +# include +#endif + +#ifndef BFS_USE_STATX +# ifdef STATX_BASIC_STATS +# define BFS_USE_STATX true +# endif +#endif + #if BFS_USE_SYS_PARAM_H # include #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. */ @@ -124,6 +137,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. */ -- cgit v1.2.3