summaryrefslogtreecommitdiffstats
path: root/util.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 /util.c
parent5a3b68d37cdc1e60802a5963340be5c5705d1f5d (diff)
downloadbfs-9754c1ab7ceebd41ffda5f8004e562f18006dc6c.tar.xz
regex: Wrap the POSIX API in a facade
Diffstat (limited to 'util.c')
-rw-r--r--util.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/util.c b/util.c
index 9f74e5a..1b363cd 100644
--- a/util.c
+++ b/util.c
@@ -260,33 +260,33 @@ bool is_nonexistence_error(int error) {
static int xrpregex(nl_item item, const char *response) {
const char *pattern = nl_langinfo(item);
if (!pattern) {
- return REG_BADPAT;
+ return -1;
}
- regex_t regex;
- int ret = bfs_regcomp(&regex, pattern, 0, BFS_REGEX_POSIX_EXTENDED);
- if (ret != 0) {
- return ret;
+ int err;
+ struct bfs_regex *regex = bfs_regcomp(pattern, BFS_REGEX_POSIX_EXTENDED, 0, &err);
+ if (!regex) {
+ return -1;
}
- ret = regexec(&regex, response, 0, NULL, 0);
- regfree(&regex);
- return ret;
+ int ret = bfs_regexec(regex, response, 0, &err);
+ bfs_regfree(regex);
+ return err ? -1 : ret;
}
/** Check if a response is affirmative or negative. */
static int xrpmatch(const char *response) {
int ret = xrpregex(NOEXPR, response);
- if (ret == 0) {
+ if (ret > 0) {
return 0;
- } else if (ret != REG_NOMATCH) {
+ } else if (ret < 0) {
return -1;
}
ret = xrpregex(YESEXPR, response);
- if (ret == 0) {
+ if (ret > 0) {
return 1;
- } else if (ret != REG_NOMATCH) {
+ } else if (ret < 0) {
return -1;
}