From d7130b3eee3e59f2e5475bbac5695cee54310c20 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 18 Apr 2024 17:30:08 -0400 Subject: config: Check for statx() --- config/header.mk | 4 +++- config/statx-syscall.c | 13 +++++++++++++ config/statx.c | 11 +++++++++++ src/stat.c | 4 ++-- src/stat.h | 8 ++------ 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 config/statx-syscall.c create mode 100644 config/statx.c diff --git a/config/header.mk b/config/header.mk index 20cb7ae..ec53dfa 100644 --- a/config/header.mk +++ b/config/header.mk @@ -17,7 +17,9 @@ HEADERS := \ ${GEN}/getprogname.h \ ${GEN}/getprogname-gnu.h \ ${GEN}/posix-spawn-addfchdir.h \ - ${GEN}/posix-spawn-addfchdir-np.h + ${GEN}/posix-spawn-addfchdir-np.h \ + ${GEN}/statx.h \ + ${GEN}/statx-syscall.h ${GEN}/config.h: ${HEADERS} ${MSG} "[ GEN] ${TGT}" diff --git a/config/statx-syscall.c b/config/statx-syscall.c new file mode 100644 index 0000000..87ec869 --- /dev/null +++ b/config/statx-syscall.c @@ -0,0 +1,13 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +#include +#include +#include +#include + +int main(void) { + struct statx sb; + syscall(SYS_statx, AT_FDCWD, ".", 0, STATX_BASIC_STATS, &sb); + return 0; +} diff --git a/config/statx.c b/config/statx.c new file mode 100644 index 0000000..65f1674 --- /dev/null +++ b/config/statx.c @@ -0,0 +1,11 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +#include +#include + +int main(void) { + struct statx sb; + statx(AT_FDCWD, ".", 0, STATX_BASIC_STATS, &sb); + return 0; +} diff --git a/src/stat.c b/src/stat.c index eca5bab..e525f24 100644 --- a/src/stat.c +++ b/src/stat.c @@ -13,7 +13,7 @@ #include #include -#if BFS_USE_STATX && !BFS_HAS_LIBC_STATX +#if BFS_USE_STATX && !BFS_HAS_STATX # include # include # include @@ -137,7 +137,7 @@ static int bfs_stat_impl(int at_fd, const char *at_path, int at_flags, struct bf * 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 BFS_HAS_LIBC_STATX +#if BFS_HAS_STATX int ret = statx(at_fd, at_path, at_flags, mask, buf); #else int ret = syscall(SYS_statx, at_fd, at_path, at_flags, mask, buf); diff --git a/src/stat.h b/src/stat.h index 1fdd263..8d7144d 100644 --- a/src/stat.h +++ b/src/stat.h @@ -17,16 +17,12 @@ #include #include -#if defined(STATX_BASIC_STATS) && (!__ANDROID__ || __ANDROID_API__ >= 30) -# define BFS_HAS_LIBC_STATX true -#elif __linux__ +#if !BFS_HAS_STATX && BFS_HAS_STATX_SYSCALL # include #endif #ifndef BFS_USE_STATX -# ifdef STATX_BASIC_STATS -# define BFS_USE_STATX true -# endif +# define BFS_USE_STATX (BFS_HAS_STATX || BFS_HAS_STATX_SYSCALL) #endif #if BFS_USE_SYS_PARAM_H -- cgit v1.2.3