summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bfstd.c6
-rw-r--r--src/bit.h2
-rw-r--r--src/fsade.c14
-rw-r--r--src/fsade.h4
-rw-r--r--src/prelude.h97
-rw-r--r--src/stat.h2
-rw-r--r--src/xspawn.c2
7 files changed, 31 insertions, 96 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index 9a3562d..a76725d 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -27,13 +27,13 @@
#include <unistd.h>
#include <wchar.h>
-#if BFS_USE_SYS_SYSMACROS_H
+#if __has_include(<sys/sysmacros.h>)
# include <sys/sysmacros.h>
-#elif BFS_USE_SYS_MKDEV_H
+#elif __has_include(<sys/mkdev.h>)
# include <sys/mkdev.h>
#endif
-#if BFS_USE_UTIL_H
+#if __has_include(<util.h>)
# include <util.h>
#endif
diff --git a/src/bit.h b/src/bit.h
index c494130..7546aba 100644
--- a/src/bit.h
+++ b/src/bit.h
@@ -12,7 +12,7 @@
#include <limits.h>
#include <stdint.h>
-#if BFS_HAS_STDBIT_H
+#if __has_include(<stdbit.h>)
# include <stdbit.h>
#endif
diff --git a/src/fsade.c b/src/fsade.c
index 11dcd9b..a5073ab 100644
--- a/src/fsade.c
+++ b/src/fsade.c
@@ -26,10 +26,12 @@
# include <selinux/selinux.h>
#endif
-#if BFS_USE_SYS_EXTATTR_H
+#if __has_include(<sys/extattr.h>)
# include <sys/extattr.h>
-#elif BFS_USE_SYS_XATTR_H
+# define BFS_USE_EXTATTR true
+#elif __has_include(<sys/xattr.h>)
# include <sys/xattr.h>
+# define BFS_USE_XATTR true
#endif
/**
@@ -344,7 +346,7 @@ int bfs_check_capabilities(const struct BFTW *ftwbuf) {
#if BFS_CAN_CHECK_XATTRS
-#if BFS_USE_SYS_EXTATTR_H
+#if BFS_USE_EXTATTR
/** Wrapper for extattr_list_{file,link}. */
static ssize_t bfs_extattr_list(const char *path, enum bfs_type type, int namespace) {
@@ -390,13 +392,13 @@ static ssize_t bfs_extattr_get(const char *path, enum bfs_type type, int namespa
#endif
}
-#endif // BFS_USE_SYS_EXTATTR_H
+#endif // BFS_USE_EXTATTR
int bfs_check_xattrs(const struct BFTW *ftwbuf) {
const char *path = fake_at(ftwbuf);
ssize_t len;
-#if BFS_USE_SYS_EXTATTR_H
+#if BFS_USE_EXTATTR
len = bfs_extattr_list(path, ftwbuf->type, EXTATTR_NAMESPACE_SYSTEM);
if (len <= 0) {
len = bfs_extattr_list(path, ftwbuf->type, EXTATTR_NAMESPACE_USER);
@@ -432,7 +434,7 @@ int bfs_check_xattr_named(const struct BFTW *ftwbuf, const char *name) {
const char *path = fake_at(ftwbuf);
ssize_t len;
-#if BFS_USE_SYS_EXTATTR_H
+#if BFS_USE_EXTATTR
len = bfs_extattr_get(path, ftwbuf->type, EXTATTR_NAMESPACE_SYSTEM, name);
if (len < 0) {
len = bfs_extattr_get(path, ftwbuf->type, EXTATTR_NAMESPACE_USER, name);
diff --git a/src/fsade.h b/src/fsade.h
index 4465017..4a9c6fa 100644
--- a/src/fsade.h
+++ b/src/fsade.h
@@ -17,7 +17,9 @@
#define BFS_CAN_CHECK_CONTEXT BFS_WITH_LIBSELINUX
-#define BFS_CAN_CHECK_XATTRS (BFS_USE_SYS_EXTATTR_H || BFS_USE_SYS_XATTR_H)
+#if __has_include(<sys/extattr.h>) || __has_include(<sys/xattr.h>)
+# define BFS_CAN_CHECK_XATTRS true
+#endif
struct BFTW;
diff --git a/src/prelude.h b/src/prelude.h
index 48f377c..7df178c 100644
--- a/src/prelude.h
+++ b/src/prelude.h
@@ -60,100 +60,31 @@ extern const char bfs_cflags[];
extern const char bfs_ldflags[];
extern const char bfs_ldlibs[];
-// Check for system headers
+// Feature detection
-#ifdef __has_include
-
-#if __has_include(<mntent.h>)
-# define BFS_HAS_MNTENT_H true
-#endif
-#if __has_include(<paths.h>)
-# define BFS_HAS_PATHS_H true
-#endif
-#if __has_include(<stdbit.h>)
-# define BFS_HAS_STDBIT_H true
-#endif
-#if __has_include(<sys/extattr.h>)
-# define BFS_HAS_SYS_EXTATTR_H true
-#endif
-#if __has_include(<sys/mkdev.h>)
-# define BFS_HAS_SYS_MKDEV_H true
-#endif
-#if __has_include(<sys/param.h>)
-# define BFS_HAS_SYS_PARAM_H true
-#endif
-#if __has_include(<sys/sysmacros.h>)
-# define BFS_HAS_SYS_SYSMACROS_H true
-#endif
-#if __has_include(<sys/xattr.h>)
-# define BFS_HAS_SYS_XATTR_H true
-#endif
-#if __has_include(<threads.h>)
-# define BFS_HAS_THREADS_H true
-#endif
-#if __has_include(<util.h>)
-# define BFS_HAS_UTIL_H true
-#endif
-
-#else // !__has_include
-
-#define BFS_HAS_MNTENT_H __GLIBC__
-#define BFS_HAS_PATHS_H true
-#define BFS_HAS_STDBIT_H (__STDC_VERSION__ >= C23)
-#define BFS_HAS_SYS_EXTATTR_H __FreeBSD__
-#define BFS_HAS_SYS_MKDEV_H false
-#define BFS_HAS_SYS_PARAM_H true
-#define BFS_HAS_SYS_SYSMACROS_H __GLIBC__
-#define BFS_HAS_SYS_XATTR_H __linux__
-#define BFS_HAS_THREADS_H (!__STDC_NO_THREADS__)
-#define BFS_HAS_UTIL_H __NetBSD__
-
-#endif // !__has_include
-
-#ifndef BFS_USE_MNTENT_H
-# define BFS_USE_MNTENT_H BFS_HAS_MNTENT_H
-#endif
-#ifndef BFS_USE_PATHS_H
-# define BFS_USE_PATHS_H BFS_HAS_PATHS_H
-#endif
-#ifndef BFS_USE_SYS_EXTATTR_H
-# define BFS_USE_SYS_EXTATTR_H BFS_HAS_SYS_EXTATTR_H
-#endif
-#ifndef BFS_USE_SYS_MKDEV_H
-# define BFS_USE_SYS_MKDEV_H BFS_HAS_SYS_MKDEV_H
-#endif
-#ifndef BFS_USE_SYS_PARAM_H
-# define BFS_USE_SYS_PARAM_H BFS_HAS_SYS_PARAM_H
-#endif
-#ifndef BFS_USE_SYS_SYSMACROS_H
-# define BFS_USE_SYS_SYSMACROS_H BFS_HAS_SYS_SYSMACROS_H
-#endif
-#ifndef BFS_USE_SYS_XATTR_H
-# define BFS_USE_SYS_XATTR_H BFS_HAS_SYS_XATTR_H
-#endif
-#ifndef BFS_USE_THREADS_H
-# define BFS_USE_THREADS_H BFS_HAS_THREADS_H
-#endif
-#ifndef BFS_USE_UTIL_H
-# define BFS_USE_UTIL_H BFS_HAS_UTIL_H
+// https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
+#ifndef __has_attribute
+# define __has_attribute(attr) false
#endif
-// Stub out feature detection on old/incompatible compilers
-
-#ifndef __has_feature
-# define __has_feature(feat) false
+// https://clang.llvm.org/docs/LanguageExtensions.html#has-builtin
+#ifndef __has_builtin
+# define __has_builtin(builtin) false
#endif
+// https://en.cppreference.com/w/c/language/attributes#Attribute_testing
#ifndef __has_c_attribute
# define __has_c_attribute(attr) false
#endif
-#ifndef __has_attribute
-# define __has_attribute(attr) false
+// https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
+#ifndef __has_feature
+# define __has_feature(feat) false
#endif
-#ifndef __has_builtin
-# define __has_builtin(builtin) false
+// https://en.cppreference.com/w/c/preprocessor/include
+#ifndef __has_include
+# define __has_include(header) false
#endif
// Sanitizer macros (GCC defines these but Clang does not)
diff --git a/src/stat.h b/src/stat.h
index 8d7144d..6a8c3f5 100644
--- a/src/stat.h
+++ b/src/stat.h
@@ -25,7 +25,7 @@
# define BFS_USE_STATX (BFS_HAS_STATX || BFS_HAS_STATX_SYSCALL)
#endif
-#if BFS_USE_SYS_PARAM_H
+#if __has_include(<sys/param.h>)
# include <sys/param.h>
#endif
diff --git a/src/xspawn.c b/src/xspawn.c
index 5e0f989..2385a6e 100644
--- a/src/xspawn.c
+++ b/src/xspawn.c
@@ -16,7 +16,7 @@
#include <sys/types.h>
#include <unistd.h>
-#if BFS_USE_PATHS_H
+#if __has_include(<paths.h>)
# include <paths.h>
#endif