summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-07-05 10:45:56 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-07-06 11:06:22 -0400
commita215ab6de0ae34db7311136404d0f9feab34ef04 (patch)
tree51470bb6b2859ee7b139b8fb81decd007944e7a8 /src/eval.c
parent66264f1518d1e19123cca23ec92eace4c7982731 (diff)
downloadbfs-a215ab6de0ae34db7311136404d0f9feab34ef04.tar.xz
Use strcmp() instead of fnmatch() if possible
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/eval.c b/src/eval.c
index 5f27681..56753af 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -547,6 +547,20 @@ bool eval_links(const struct bfs_expr *expr, struct bfs_eval *state) {
return bfs_expr_cmp(expr, statbuf->nlink);
}
+/** Common code for fnmatch() tests. */
+static bool eval_fnmatch(const struct bfs_expr *expr, const char *str) {
+ if (expr->literal) {
+#ifdef FNM_CASEFOLD
+ if (expr->fnm_flags & FNM_CASEFOLD) {
+ return strcasecmp(expr->pattern, str) == 0;
+ }
+#endif
+ return strcmp(expr->pattern, str) == 0;
+ } else {
+ return fnmatch(expr->pattern, str, expr->fnm_flags) == 0;
+ }
+}
+
/**
* -i?lname test.
*/
@@ -568,7 +582,7 @@ bool eval_lname(const struct bfs_expr *expr, struct bfs_eval *state) {
goto done;
}
- ret = fnmatch(expr->argv[1], name, expr->num) == 0;
+ ret = eval_fnmatch(expr, name);
done:
free(name);
@@ -589,7 +603,7 @@ bool eval_name(const struct bfs_expr *expr, struct bfs_eval *state) {
name = copy = xbasename(name);
}
- bool ret = fnmatch(expr->argv[1], name, expr->num) == 0;
+ bool ret = eval_fnmatch(expr, name);
free(copy);
return ret;
}
@@ -598,8 +612,7 @@ bool eval_name(const struct bfs_expr *expr, struct bfs_eval *state) {
* -i?path test.
*/
bool eval_path(const struct bfs_expr *expr, struct bfs_eval *state) {
- const struct BFTW *ftwbuf = state->ftwbuf;
- return fnmatch(expr->argv[1], ftwbuf->path, expr->num) == 0;
+ return eval_fnmatch(expr, state->ftwbuf->path);
}
/**