From 98fce1fb43d66f5c74090094be589fe7f859ed20 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 7 Nov 2020 22:51:46 +0100 Subject: Compatibility function for faccessat --- Compat.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'Compat.c') diff --git a/Compat.c b/Compat.c index 096b938a..37e7c042 100644 --- a/Compat.c +++ b/Compat.c @@ -9,6 +9,7 @@ in the source distribution for its full text. #include "Compat.h" +#include #include // IWYU pragma: keep #include #include @@ -17,6 +18,41 @@ in the source distribution for its full text. #include "XUtils.h" // IWYU pragma: keep +int Compat_faccessat(int dirfd, + const char* pathname, + int mode, + int flags) { + int ret; + +#ifdef HAVE_FACCESSAT + + // Implementation note: AT_SYMLINK_NOFOLLOW unsupported on FreeBSD, fallback to lstat in that case + + errno = 0; + + ret = faccessat(dirfd, pathname, mode, flags); + if (!ret || errno != EINVAL) + return ret; + +#endif + + // Error out on unsupported configurations + if (dirfd != AT_FDCWD || mode != F_OK) { + errno = EINVAL; + return -1; + } + + // Fallback to stat(2)/lstat(2) depending on flags + struct stat statinfo; + if(flags) { + ret = lstat(pathname, &statinfo); + } else { + ret = stat(pathname, &statinfo); + } + + return ret; +} + int Compat_fstatat(int dirfd, const char* dirpath, const char* pathname, -- cgit v1.2.3