summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Misc.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/util/Misc.c b/src/util/Misc.c
index 9d92a447..f4418799 100644
--- a/src/util/Misc.c
+++ b/src/util/Misc.c
@@ -1151,23 +1151,32 @@ int CCTK_RegexMatch(const char *string,
int status;
regex_t re;
- if (regcomp(&re, pattern, REG_EXTENDED) == 0)
+ /* BSD says: an empty string is not a legal regular expression.
+ Handle this case specially. */
+ if (strcmp(pattern, "") == 0)
{
- status = regexec(&re, string, (size_t)nmatch, pmatch, 0);
- regfree(&re);
- if (status != 0)
+ retval = 1; /* report success */
+ }
+ else
+ {
+ if (regcomp(&re, pattern, REG_EXTENDED) == 0)
{
- retval = 0; /* report error */
+ status = regexec(&re, string, (size_t)nmatch, pmatch, 0);
+ regfree(&re);
+ if (status != 0)
+ {
+ retval = 0; /* report error */
+ }
+ else
+ {
+ retval = 1;
+ }
}
else
{
- retval = 1;
+ retval = 0;
}
}
- else
- {
- retval = 0;
- }
return retval;
}