summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-02-21 15:25:27 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-02-21 16:12:07 -0500
commit9754c1ab7ceebd41ffda5f8004e562f18006dc6c (patch)
treebe623cc6de520ed5578458e58a9d774c75b0f296 /eval.c
parent5a3b68d37cdc1e60802a5963340be5c5705d1f5d (diff)
downloadbfs-9754c1ab7ceebd41ffda5f8004e562f18006dc6c.tar.xz
regex: Wrap the POSIX API in a facade
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/eval.c b/eval.c
index f7de940..e812dc6 100644
--- a/eval.c
+++ b/eval.c
@@ -827,20 +827,10 @@ bool eval_quit(const struct expr *expr, struct eval_state *state) {
*/
bool eval_regex(const struct expr *expr, struct eval_state *state) {
const char *path = state->ftwbuf->path;
- size_t len = strlen(path);
- regmatch_t match = {
- .rm_so = 0,
- .rm_eo = len,
- };
- int flags = 0;
-#ifdef REG_STARTEND
- flags |= REG_STARTEND;
-#endif
- int err = regexec(expr->regex, path, 1, &match, flags);
- if (err == 0) {
- return match.rm_so == 0 && (size_t)match.rm_eo == len;
- } else if (err != REG_NOMATCH) {
+ int err;
+ bool ret = bfs_regexec(expr->regex, path, BFS_REGEX_ANCHOR, &err);
+ if (err) {
char *str = bfs_regerror(err, expr->regex);
if (str) {
eval_error(state, "%s.\n", str);
@@ -848,11 +838,9 @@ bool eval_regex(const struct expr *expr, struct eval_state *state) {
} else {
eval_error(state, "bfs_regerror(): %m.\n");
}
-
- *state->ret = EXIT_FAILURE;
}
- return false;
+ return ret;
}
/**