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 /util.c | |
parent | 5a3b68d37cdc1e60802a5963340be5c5705d1f5d (diff) | |
download | bfs-9754c1ab7ceebd41ffda5f8004e562f18006dc6c.tar.xz |
regex: Wrap the POSIX API in a facade
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -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(®ex, 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(®ex, response, 0, NULL, 0); - regfree(®ex); - 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; } |