From 9f6f391358e3d8f66ebd750250479bebebe4d0d4 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 6 Nov 2022 10:40:33 -0500 Subject: util: Use fewer BFS_*() wrappers for feature testing --- src/dir.c | 2 +- src/fsade.c | 2 +- src/stat.c | 4 ++-- src/util.h | 36 ++++++++++++++---------------------- src/xregex.c | 2 +- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/dir.c b/src/dir.c index 024e767..6d4a325 100644 --- a/src/dir.c +++ b/src/dir.c @@ -229,7 +229,7 @@ int bfs_readdir(struct bfs_dir *dir, struct bfs_dirent *de) { char *buf = (char *)(dir + 1); if (dir->pos >= dir->size) { -#if BFS_HAS_FEATURE(memory_sanitizer, false) +#if __has_feature(memory_sanitizer) // Make sure msan knows the buffer is initialized memset(buf, 0, BUF_SIZE); #endif diff --git a/src/fsade.c b/src/fsade.c index 1444cf4..9e5374f 100644 --- a/src/fsade.c +++ b/src/fsade.c @@ -172,7 +172,7 @@ static int bfs_check_acl_type(acl_t acl, acl_type_t type) { #if __FreeBSD__ int trivial; -#if BFS_HAS_FEATURE(memory_sanitizer, false) +#if __has_feature(memory_sanitizer) // msan seems to be missing an interceptor for acl_is_trivial_np() trivial = 0; #endif diff --git a/src/stat.c b/src/stat.c index b172780..ab3282a 100644 --- a/src/stat.c +++ b/src/stat.c @@ -156,7 +156,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_FEATURE(memory_sanitizer, false) +#if __has_feature(memory_sanitizer) // -fsanitize=memory doesn't know about statx(), so tell it the memory // got initialized memset(buf, 0, sizeof(*buf)); @@ -310,7 +310,7 @@ int bfs_stat(int at_fd, const char *at_path, enum bfs_stat_flags flags, struct b at_flags |= AT_SYMLINK_NOFOLLOW; } -#if defined(AT_NO_AUTOMOUNT) && (!__GNU__ || BFS_GLIBC_PREREQ(2, 35)) +#if defined(AT_NO_AUTOMOUNT) && (!__GNU__ || __GLIBC_PREREQ(2, 35)) at_flags |= AT_NO_AUTOMOUNT; #endif diff --git a/src/util.h b/src/util.h index ac08e4d..ffa5bcc 100644 --- a/src/util.h +++ b/src/util.h @@ -30,28 +30,22 @@ // Some portability concerns -#ifdef __has_feature -# define BFS_HAS_FEATURE(feature, fallback) __has_feature(feature) -#else -# define BFS_HAS_FEATURE(feature, fallback) fallback +#ifndef __has_feature +# define __has_feature(feat) false #endif -#ifdef __has_include -# define BFS_HAS_INCLUDE(header, fallback) __has_include(header) -#else -# define BFS_HAS_INCLUDE(header, fallback) fallback +#ifndef __has_c_attribute +# define __has_c_attribute(attr) false #endif -#ifdef __has_c_attribute -# define BFS_HAS_C_ATTRIBUTE(attr) __has_c_attribute(attr) -#else -# define BFS_HAS_C_ATTRIBUTE(attr) false +#ifndef __has_attribute +# define __has_attribute(attr) false #endif -#if __GNUC__ && defined(__has_attribute) -# define BFS_HAS_GNU_ATTRIBUTE(attr) __has_attribute(attr) +#ifdef __has_include +# define BFS_HAS_INCLUDE(header, fallback) __has_include(header) #else -# define BFS_HAS_GNU_ATTRIBUTE(attr) false +# define BFS_HAS_INCLUDE(header, fallback) fallback #endif #ifndef BFS_HAS_MNTENT @@ -94,10 +88,8 @@ # define BFS_HAS_UTIL BFS_HAS_INCLUDE(, __NetBSD__) #endif -#ifdef __GLIBC_PREREQ -# define BFS_GLIBC_PREREQ(maj, min) __GLIBC_PREREQ(maj, min) -#else -# define BFS_GLIBC_PREREQ(maj, min) false +#ifndef __GLIBC_PREREQ +# define __GLIBC_PREREQ(maj, min) false #endif #if !defined(FNM_CASEFOLD) && defined(FNM_IGNORECASE) @@ -108,9 +100,9 @@ # define O_DIRECTORY 0 #endif -#if BFS_HAS_C_ATTRIBUTE(fallthrough) +#if __has_c_attribute(fallthrough) # define BFS_FALLTHROUGH [[fallthrough]] -#elif BFS_HAS_GNU_ATTRIBUTE(fallthrough) +#elif __has_attribute(fallthrough) # define BFS_FALLTHROUGH __attribute__((fallthrough)) #else # define BFS_FALLTHROUGH ((void)0) @@ -119,7 +111,7 @@ /** * Adds compiler warnings for bad printf()-style function calls, if supported. */ -#if BFS_HAS_GNU_ATTRIBUTE(format) +#if __has_attribute(format) # define BFS_FORMATTER(fmt, args) __attribute__((format(printf, fmt, args))) #else # define BFS_FORMATTER(fmt, args) diff --git a/src/xregex.c b/src/xregex.c index 3c3cf35..4fa098d 100644 --- a/src/xregex.c +++ b/src/xregex.c @@ -188,7 +188,7 @@ int bfs_regcomp(struct bfs_regex **preg, const char *pattern, enum bfs_regex_typ cflags |= REG_ICASE; } -#if BFS_HAS_FEATURE(memory_sanitizer, false) +#if __has_feature(memory_sanitizer) // https://github.com/google/sanitizers/issues/1496 memset(®ex->impl, 0, sizeof(regex->impl)); #endif -- cgit v1.2.3