diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-01-16 11:06:28 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-01-18 20:07:40 -0500 |
commit | 3fa8f1a22ad120322bbc68823ca9759d8939b131 (patch) | |
tree | 6c26b40f43ef7987582de08980f705414ef7abfb /src/stat.h | |
parent | 40e195c1bd60737964bb2b8ab25780a02003f8e1 (diff) | |
download | bfs-3fa8f1a22ad120322bbc68823ca9759d8939b131.tar.xz |
stat: Expose bfs_stat{,x}_convert()
Diffstat (limited to 'src/stat.h')
-rw-r--r-- | src/stat.h | 41 |
1 files changed, 33 insertions, 8 deletions
@@ -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); |