aboutsummaryrefslogtreecommitdiff
path: root/lib/xwrap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r--lib/xwrap.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 1e39c1bc..be57097d 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -922,11 +922,18 @@ long long xparsemillitime(char *arg)
// Compile a regular expression into a regex_t
void xregcomp(regex_t *preg, char *regex, int cflags)
{
- int rc = regcomp(preg, regex, cflags);
+ int rc;
+
+ // BSD regex implementations don't support the empty regex (which isn't
+ // allowed in the POSIX grammar), but glibc does. Fake it for BSD.
+ if (!*regex) {
+ regex = "()";
+ cflags |= REG_EXTENDED;
+ }
- if (rc) {
+ if ((rc = regcomp(preg, regex, cflags))) {
regerror(rc, preg, libbuf, sizeof(libbuf));
- error_exit("xregcomp: %s", libbuf);
+ error_exit("bad regex: %s", libbuf);
}
}