summaryrefslogtreecommitdiff
path: root/usr.bin/rdist/docmd.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-05-06 22:10:12 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-05-06 22:10:12 +0000
commit237f3ca12c2499b607c061f095929774144ec0f9 (patch)
treef5b53886bbc0ff78c0d89463bd55b24922148b67 /usr.bin/rdist/docmd.c
parent12e8b31474927177f0c8e63e2d6d8d6eac721265 (diff)
use POSIX regex
Diffstat (limited to 'usr.bin/rdist/docmd.c')
-rw-r--r--usr.bin/rdist/docmd.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/usr.bin/rdist/docmd.c b/usr.bin/rdist/docmd.c
index fdbe5801630..5772c5bb36b 100644
--- a/usr.bin/rdist/docmd.c
+++ b/usr.bin/rdist/docmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: docmd.c,v 1.13 2003/04/19 17:22:29 millert Exp $ */
+/* $OpenBSD: docmd.c,v 1.14 2003/05/06 22:10:11 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: docmd.c,v 6.86 1996/01/30 02:29:43 mcooper Exp $";
#else
static char RCSid[] =
-"$OpenBSD: docmd.c,v 1.13 2003/04/19 17:22:29 millert Exp $";
+"$OpenBSD: docmd.c,v 1.14 2003/05/06 22:10:11 millert Exp $";
#endif
static char sccsid[] = "@(#)docmd.c 5.1 (Berkeley) 6/6/85";
@@ -836,15 +836,31 @@ extern int except(file)
}
if (sc->sc_type == PATTERN) {
for (nl = sc->sc_args; nl != NULL; nl = nl->n_next) {
- char *cp, *re_comp();
-
- if ((cp = re_comp(nl->n_name)) != NULL) {
+ char ebuf[BUFSIZ];
+ int ecode = 0;
+
+ /* allocate and compile n_regex as needed */
+ if (nl->n_regex == NULL) {
+ nl->n_regex = (regex_t *)
+ xmalloc(sizeof(regex_t));
+ ecode = regcomp(nl->n_regex, nl->n_name,
+ REG_NOSUB);
+ }
+ if (ecode == 0) {
+ ecode = regexec(nl->n_regex, file, 0,
+ NULL, 0);
+ }
+ switch (ecode) {
+ case REG_NOMATCH:
+ break;
+ case 0:
+ return(1); /* match! */
+ default:
+ regerror(ecode, nl->n_regex, ebuf,
+ sizeof(ebuf));
error("Regex error \"%s\" for \"%s\".",
- cp, nl->n_name);
- return(0);
+ ebuf, nl->n_name);
}
- if (re_exec(file) > 0)
- return(1);
}
}
}