summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.h6
-rw-r--r--src/diag.h6
-rw-r--r--src/dir.c28
-rw-r--r--src/mtab.c28
-rw-r--r--src/parse.c4
-rw-r--r--src/stat.c16
-rw-r--r--src/trie.c2
-rw-r--r--src/xregex.c14
8 files changed, 53 insertions, 51 deletions
diff --git a/src/config.h b/src/config.h
index 1671a0d..79bd931 100644
--- a/src/config.h
+++ b/src/config.h
@@ -189,8 +189,10 @@
/**
* Check if function multiversioning via GNU indirect functions (ifunc) is supported.
*/
-#if !defined(BFS_TARGET_CLONES) && __has_attribute(target_clones) && (__GLIBC__ || __FreeBSD__ || __NetBSD__)
-# define BFS_TARGET_CLONES true
+#ifndef BFS_USE_TARGET_CLONES
+# if __has_attribute(target_clones) && (__GLIBC__ || __FreeBSD__ || __NetBSD__)
+# define BFS_USE_TARGET_CLONES true
+# endif
#endif
/**
diff --git a/src/diag.h b/src/diag.h
index 8d02da6..c909da5 100644
--- a/src/diag.h
+++ b/src/diag.h
@@ -18,8 +18,8 @@
#if __STDC_VERSION__ >= 202311L
# define bfs_static_assert static_assert
#else
-# define bfs_static_assert(...) BFS_STATIC_ASSERT(__VA_ARGS__, #__VA_ARGS__, )
-# define BFS_STATIC_ASSERT(expr, msg, ...) _Static_assert(expr, msg)
+# define bfs_static_assert(...) bfs_static_assert_(__VA_ARGS__, #__VA_ARGS__, )
+# define bfs_static_assert_(expr, msg, ...) _Static_assert(expr, msg)
#endif
/**
@@ -62,8 +62,6 @@ noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...);
# define bfs_bug bfs_abort
#endif
-
-
/**
* Unconditional assert.
*/
diff --git a/src/dir.c b/src/dir.c
index a24b572..685bac5 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -15,11 +15,11 @@
#include <sys/stat.h>
#include <unistd.h>
-#ifndef BFS_GETDENTS
-# define BFS_GETDENTS (__linux__ || __FreeBSD__)
+#ifndef BFS_USE_GETDENTS
+# define BFS_USE_GETDENTS (__linux__ || __FreeBSD__)
#endif
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
# if __linux__
# include <sys/syscall.h>
# endif
@@ -43,9 +43,9 @@ static ssize_t bfs_getdents(int fd, void *buf, size_t size) {
return ret;
}
-#endif // BFS_GETDENTS
+#endif // BFS_USE_GETDENTS
-#if BFS_GETDENTS && __linux__
+#if BFS_USE_GETDENTS && __linux__
/** Directory entry type for bfs_getdents() */
typedef struct dirent64 sys_dirent;
#else
@@ -101,7 +101,7 @@ enum bfs_type bfs_mode_to_type(mode_t mode) {
}
struct bfs_dir {
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
alignas(sys_dirent) int fd;
unsigned short pos;
unsigned short size;
@@ -114,7 +114,7 @@ struct bfs_dir {
bool eof;
};
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
# define DIR_SIZE (64 << 10)
# define BUF_SIZE (DIR_SIZE - sizeof(struct bfs_dir))
#else
@@ -143,7 +143,7 @@ int bfs_opendir(struct bfs_dir *dir, int at_fd, const char *at_path) {
return -1;
}
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
dir->fd = fd;
dir->pos = 0;
dir->size = 0;
@@ -163,7 +163,7 @@ int bfs_opendir(struct bfs_dir *dir, int at_fd, const char *at_path) {
}
int bfs_dirfd(const struct bfs_dir *dir) {
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
return dir->fd;
#else
return dirfd(dir->dir);
@@ -171,7 +171,7 @@ int bfs_dirfd(const struct bfs_dir *dir) {
}
int bfs_polldir(struct bfs_dir *dir) {
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
if (dir->pos < dir->size) {
return 1;
} else if (dir->eof) {
@@ -203,7 +203,7 @@ int bfs_polldir(struct bfs_dir *dir) {
}
return 1;
-#else // !BFS_GETDENTS
+#else // !BFS_USE_GETDENTS
if (dir->de) {
return 1;
} else if (dir->eof) {
@@ -227,7 +227,7 @@ int bfs_polldir(struct bfs_dir *dir) {
static int bfs_getdent(struct bfs_dir *dir, const sys_dirent **de) {
int ret = bfs_polldir(dir);
if (ret > 0) {
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
char *buf = (char *)(dir + 1);
*de = (const sys_dirent *)(buf + dir->pos);
dir->pos += (*de)->d_reclen;
@@ -283,7 +283,7 @@ int bfs_readdir(struct bfs_dir *dir, struct bfs_dirent *de) {
}
int bfs_closedir(struct bfs_dir *dir) {
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
int ret = xclose(dir->fd);
#else
int ret = closedir(dir->dir);
@@ -297,7 +297,7 @@ int bfs_closedir(struct bfs_dir *dir) {
}
int bfs_fdclosedir(struct bfs_dir *dir, bool same_fd) {
-#if BFS_GETDENTS
+#if BFS_USE_GETDENTS
int ret = dir->fd;
#elif __FreeBSD__
int ret = fdclosedir(dir->dir);
diff --git a/src/mtab.c b/src/mtab.c
index e5c25ba..384fdfc 100644
--- a/src/mtab.c
+++ b/src/mtab.c
@@ -14,22 +14,22 @@
#include <string.h>
#include <sys/types.h>
-#if BFS_USE_MNTENT_H
-# define BFS_MNTENT 1
-#elif BSD
-# define BFS_MNTINFO 1
-#elif __SVR4
-# define BFS_MNTTAB 1
+#if !defined(BFS_USE_MNTENT) && BFS_USE_MNTENT_H
+# define BFS_USE_MNTENT true
+#elif !defined(BFS_USE_MNTINFO) && BSD
+# define BFS_USE_MNTINFO true
+#elif !defined(BFS_USE_MNTTAB) && __SVR4
+# define BFS_USE_MNTTAB true
#endif
-#if BFS_MNTENT
+#if BFS_USE_MNTENT
# include <mntent.h>
# include <paths.h>
# include <stdio.h>
-#elif BFS_MNTINFO
+#elif BFS_USE_MNTINFO
# include <sys/mount.h>
# include <sys/ucred.h>
-#elif BFS_MNTTAB
+#elif BFS_USE_MNTTAB
# include <stdio.h>
# include <sys/mnttab.h>
#endif
@@ -45,7 +45,7 @@ struct bfs_mtab_entry {
};
struct bfs_mtab {
- /** The list of mount points. */
+ /** The array of mount points. */
struct bfs_mtab_entry *entries;
/** The basenames of every mount point. */
struct trie names;
@@ -59,7 +59,7 @@ struct bfs_mtab {
/**
* Add an entry to the mount table.
*/
-static int bfs_mtab_add(struct bfs_mtab *mtab, const char *path, const char *type) {
+static inline int bfs_mtab_add(struct bfs_mtab *mtab, const char *path, const char *type) {
struct bfs_mtab_entry entry = {
.path = strdup(path),
.type = strdup(type),
@@ -98,7 +98,7 @@ struct bfs_mtab *bfs_mtab_parse(void) {
int error = 0;
-#if BFS_MNTENT
+#if BFS_USE_MNTENT
FILE *file = setmntent(_PATH_MOUNTED, "r");
if (!file) {
@@ -121,7 +121,7 @@ struct bfs_mtab *bfs_mtab_parse(void) {
endmntent(file);
-#elif BFS_MNTINFO
+#elif BFS_USE_MNTINFO
#if __NetBSD__
typedef struct statvfs bfs_statfs;
@@ -143,7 +143,7 @@ struct bfs_mtab *bfs_mtab_parse(void) {
}
}
-#elif BFS_MNTTAB
+#elif BFS_USE_MNTTAB
FILE *file = xfopen(MNTTAB, O_RDONLY | O_CLOEXEC);
if (!file) {
diff --git a/src/parse.c b/src/parse.c
index cf4f696..1321270 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -2296,7 +2296,7 @@ static struct bfs_expr *parse_regextype(struct parser_state *state, int arg1, in
state->regex_type = BFS_REGEX_POSIX_BASIC;
} else if (strcmp(type, "posix-extended") == 0) {
state->regex_type = BFS_REGEX_POSIX_EXTENDED;
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
} else if (strcmp(type, "emacs") == 0) {
state->regex_type = BFS_REGEX_EMACS;
} else if (strcmp(type, "grep") == 0) {
@@ -2318,7 +2318,7 @@ list_types:
cfprintf(cfile, " ${bld}posix-basic${rs}: POSIX basic regular expressions (BRE)\n");
cfprintf(cfile, " ${bld}posix-extended${rs}: POSIX extended regular expressions (ERE)\n");
cfprintf(cfile, " ${bld}ed${rs}: Like ${grn}ed${rs} (same as ${bld}posix-basic${rs})\n");
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
cfprintf(cfile, " ${bld}emacs${rs}: Like ${grn}emacs${rs}\n");
cfprintf(cfile, " ${bld}grep${rs}: Like ${grn}grep${rs}\n");
#endif
diff --git a/src/stat.c b/src/stat.c
index e3e5aaa..7a413cd 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -14,15 +14,17 @@
#include <sys/stat.h>
#if defined(STATX_BASIC_STATS) && (!__ANDROID__ || __ANDROID_API__ >= 30)
-# define BFS_LIBC_STATX true
+# define BFS_HAS_LIBC_STATX true
#elif __linux__
# include <linux/stat.h>
# include <sys/syscall.h>
# include <unistd.h>
#endif
-#if BFS_LIBC_STATX || defined(SYS_statx)
-# define BFS_STATX true
+#ifndef BFS_USE_STATX
+# if BFS_HAS_LIBC_STATX || defined(SYS_statx)
+# define BFS_USE_STATX true
+# endif
#endif
const char *bfs_stat_field_name(enum bfs_stat_field field) {
@@ -128,13 +130,13 @@ static int bfs_stat_impl(int at_fd, const char *at_path, int at_flags, struct bf
return ret;
}
-#if BFS_STATX
+#if BFS_USE_STATX
/**
* 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_LIBC_STATX
+#if BFS_HAS_LIBC_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);
@@ -242,13 +244,13 @@ static int bfs_statx_impl(int at_fd, const char *at_path, int at_flags, struct b
return ret;
}
-#endif // BFS_STATX
+#endif // BFS_USE_STATX
/**
* Calls the stat() implementation with explicit flags.
*/
static int bfs_stat_explicit(int at_fd, const char *at_path, int at_flags, int x_flags, struct bfs_stat *buf) {
-#if BFS_STATX
+#if BFS_USE_STATX
static atomic bool has_statx = true;
if (load(&has_statx, relaxed)) {
diff --git a/src/trie.c b/src/trie.c
index 992d42b..0206509 100644
--- a/src/trie.c
+++ b/src/trie.c
@@ -94,7 +94,7 @@
bfs_static_assert(CHAR_WIDTH == 8);
-#if BFS_TARGET_CLONES && (__i386__ || __x86_64__)
+#if BFS_USE_TARGET_CLONES && (__i386__ || __x86_64__)
# define TARGET_CLONES_POPCNT __attribute__((target_clones("popcnt", "default")))
#else
# define TARGET_CLONES_POPCNT
diff --git a/src/xregex.c b/src/xregex.c
index ab5f793..88df082 100644
--- a/src/xregex.c
+++ b/src/xregex.c
@@ -11,7 +11,7 @@
#include <stdlib.h>
#include <string.h>
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
# include <langinfo.h>
# include <oniguruma.h>
#else
@@ -19,7 +19,7 @@
#endif
struct bfs_regex {
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
unsigned char *pattern;
OnigRegex impl;
int err;
@@ -30,7 +30,7 @@ struct bfs_regex {
#endif
};
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
static int bfs_onig_status;
static OnigEncoding bfs_onig_enc;
@@ -121,7 +121,7 @@ int bfs_regcomp(struct bfs_regex **preg, const char *pattern, enum bfs_regex_typ
return -1;
}
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
// onig_error_code_to_str() says
//
// don't call this after the pattern argument of onig_new() is freed
@@ -204,7 +204,7 @@ fail:
int bfs_regexec(struct bfs_regex *regex, const char *str, enum bfs_regexec_flags flags) {
size_t len = strlen(str);
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
const unsigned char *ustr = (const unsigned char *)str;
const unsigned char *end = ustr + len;
@@ -263,7 +263,7 @@ int bfs_regexec(struct bfs_regex *regex, const char *str, enum bfs_regexec_flags
void bfs_regfree(struct bfs_regex *regex) {
if (regex) {
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
onig_free(regex->impl);
free(regex->pattern);
#else
@@ -278,7 +278,7 @@ char *bfs_regerror(const struct bfs_regex *regex) {
return strdup(strerror(ENOMEM));
}
-#if BFS_WITH_ONIGURUMA
+#if BFS_USE_ONIGURUMA
unsigned char *str = malloc(ONIG_MAX_ERROR_MESSAGE_LEN);
if (str) {
onig_error_code_to_str(str, regex->err, &regex->einfo);