diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1999-08-02 17:10:48 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1999-08-02 17:10:48 +0000 |
commit | 903d8d7a4265eb1a319e39ac2ab1bd4f0ebedd8a (patch) | |
tree | fc7dc50ddf5a6436899ea766f712bc838d40f322 /lib | |
parent | 835096904992fef0e0da9dc303f1f2d4d3f5eef1 (diff) |
Add a hook to regexp/regerror.c for overriding the default regerror()
function.
Add support for overriding the default regerror() function in 4.3/regex.c,
and avoiding free()ing things multiple times.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libcompat/4.3/regex.c | 22 | ||||
-rw-r--r-- | lib/libcompat/regexp/regerror.c | 20 |
2 files changed, 31 insertions, 11 deletions
diff --git a/lib/libcompat/4.3/regex.c b/lib/libcompat/4.3/regex.c index 8b836d6a962..31a04ca797c 100644 --- a/lib/libcompat/4.3/regex.c +++ b/lib/libcompat/4.3/regex.c @@ -43,7 +43,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char sccsid[] = "from: @(#)regex.c 5.1 (Berkeley) 3/29/92";*/ -static char rcsid[] = "$Id: regex.c,v 1.1 1995/10/18 08:42:34 deraadt Exp $"; +static char rcsid[] = "$Id: regex.c,v 1.2 1999/08/02 17:10:47 downsj Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -56,18 +56,26 @@ static regexp *re_regexp; static int re_goterr; static char *re_errstr; +static void re_error __P((const char *)); + char * re_comp(s) const char *s; { if (s == NULL) return (NULL); - if (re_regexp) + if (re_regexp) { free(re_regexp); - if (re_errstr) + re_regexp = NULL; + } + if (re_errstr) { free(re_errstr); + re_errstr = NULL; + } + v8_setregerror(re_error); + re_goterr = 0; - re_regexp = regcomp(s); + re_regexp = v8_regcomp(s); return (re_goterr ? re_errstr : NULL); } @@ -78,12 +86,12 @@ re_exec(s) int rc; re_goterr = 0; - rc = regexec(re_regexp, s); + rc = v8_regexec(re_regexp, s); return (re_goterr ? -1 : rc); } -void -regerror(s) +static void +re_error(s) const char *s; { re_goterr = 1; diff --git a/lib/libcompat/regexp/regerror.c b/lib/libcompat/regexp/regerror.c index 1063b9722d2..c1b96806d47 100644 --- a/lib/libcompat/regexp/regerror.c +++ b/lib/libcompat/regexp/regerror.c @@ -1,15 +1,27 @@ -/* $OpenBSD: regerror.c,v 1.2 1996/07/24 05:39:11 downsj Exp $ */ +/* $OpenBSD: regerror.c,v 1.3 1999/08/02 17:10:47 downsj Exp $ */ #ifndef lint -static char *rcsid = "$OpenBSD: regerror.c,v 1.2 1996/07/24 05:39:11 downsj Exp $"; +static char *rcsid = "$OpenBSD: regerror.c,v 1.3 1999/08/02 17:10:47 downsj Exp $"; #endif /* not lint */ #include <regexp.h> #include <stdio.h> +static void (*_new_regerror)() = NULL; + void v8_regerror(s) -const char *s; + const char *s; { - warnx(s); + if (_new_regerror != NULL) + _new_regerror(s); + else + warnx(s); return; } + +void +v8_setregerror(f) + void (*f)(); +{ + _new_regerror = f; +} |