diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2018-07-11 17:54:45 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2018-07-11 17:54:45 -0400 |
commit | f25efd83a941d143dff939d353113415b3a7fa90 (patch) | |
tree | d39a593e7ab9b8f3ef2fb4956a1a380cde7cf469 /stat.c | |
parent | 9caf477f12e730af5181587656f34c316152a2a6 (diff) | |
download | bfs-f25efd83a941d143dff939d353113415b3a7fa90.tar.xz |
stat: Support the glibc statx() wrapper
glibc 2.28 will ship with a wrapper for the statx() system call.
Currently the build is broken against it, because sys/stat.h suddenly
declares all the same types that linux/stat.h does. Fix it by taking
the sys/stat.h ones if they exist.
Fixes #35
Diffstat (limited to 'stat.c')
-rw-r--r-- | stat.c | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -23,11 +23,19 @@ #include <sys/stat.h> #include <unistd.h> -#if __linux__ +#ifdef STATX_BASIC_STATS +# define HAVE_STATX true +#elif __linux__ # include <linux/stat.h> # include <sys/syscall.h> +#endif + +#if HAVE_STATX || defined(__NR_statx) +# define HAVE_BFS_STATX true # include <sys/sysmacros.h> -#elif __APPLE__ +#endif + +#if __APPLE__ # define st_atim st_atimespec # define st_ctim st_ctimespec # define st_mtim st_mtimespec @@ -108,13 +116,17 @@ static int bfs_stat_impl(int at_fd, const char *at_path, int at_flags, enum bfs_ return ret; } -#ifdef __NR_statx +#if HAVE_BFS_STATX /** - * Wrapper for the statx() system call, which has no native glibc wrapper. + * Wrapper for the statx() system call, which had no glibc wrapper prior to 2.28. */ static int bfs_statx(int at_fd, const char *at_path, int at_flags, unsigned int mask, struct statx *buf) { +#if HAVE_STATX + return statx(at_fd, at_path, at_flags, mask, buf); +#else return syscall(__NR_statx, at_fd, at_path, at_flags, mask, buf); +#endif } /** @@ -210,10 +222,10 @@ static int bfs_statx_impl(int at_fd, const char *at_path, int at_flags, enum bfs return ret; } -#endif // STATX_BASIC_STATS +#endif // HAVE_BFS_STATX int bfs_stat(int at_fd, const char *at_path, int at_flags, enum bfs_stat_flag flags, struct bfs_stat *buf) { -#ifdef __NR_statx +#if HAVE_BFS_STATX static bool has_statx = true; if (has_statx) { |