diff options
author | Elliott Hughes <enh@google.com> | 2019-07-30 09:56:28 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-07-31 11:28:40 -0500 |
commit | d8a46b5b6befc72bb7142850fc4f4c1fd7fb1c1b (patch) | |
tree | d343b6df9619c1edf84c7648886a0f3d8fcb80c9 /lib | |
parent | 88468a07124a5cda235037249a65a32c4c95f1dd (diff) | |
download | toybox-d8a46b5b6befc72bb7142850fc4f4c1fd7fb1c1b.tar.gz |
Move the empty regex workaround into xregcomp.
No current caller except grep needs this, but consistency seems like a
good idea.
Also change the xregcomp error message to be a bit more human-readable,
rather than mention an implementation detail.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/xwrap.c | 13 |
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); } } |