diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-02-21 15:25:27 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-02-21 16:12:07 -0500 |
commit | 9754c1ab7ceebd41ffda5f8004e562f18006dc6c (patch) | |
tree | be623cc6de520ed5578458e58a9d774c75b0f296 /eval.c | |
parent | 5a3b68d37cdc1e60802a5963340be5c5705d1f5d (diff) | |
download | bfs-9754c1ab7ceebd41ffda5f8004e562f18006dc6c.tar.xz |
regex: Wrap the POSIX API in a facade
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 20 |
1 files changed, 4 insertions, 16 deletions
@@ -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; } /** |