xref: /minix3/external/bsd/nvi/dist/regex/regfree.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: regfree.c,v 1.5 2014/01/26 21:47:00 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
484d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994
584d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
684d9c625SLionel Sambuc  *
784d9c625SLionel Sambuc  * This code is derived from software contributed to Berkeley by
884d9c625SLionel Sambuc  * Henry Spencer of the University of Toronto.
984d9c625SLionel Sambuc  *
1084d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
1184d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions
1284d9c625SLionel Sambuc  * are met:
1384d9c625SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1484d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1584d9c625SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1684d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1784d9c625SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1884d9c625SLionel Sambuc  * 3. All advertising materials mentioning features or use of this software
1984d9c625SLionel Sambuc  *    must display the following acknowledgement:
2084d9c625SLionel Sambuc  *	This product includes software developed by the University of
2184d9c625SLionel Sambuc  *	California, Berkeley and its contributors.
2284d9c625SLionel Sambuc  * 4. Neither the name of the University nor the names of its contributors
2384d9c625SLionel Sambuc  *    may be used to endorse or promote products derived from this software
2484d9c625SLionel Sambuc  *    without specific prior written permission.
2584d9c625SLionel Sambuc  *
2684d9c625SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2784d9c625SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2884d9c625SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2984d9c625SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3084d9c625SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3184d9c625SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3284d9c625SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3384d9c625SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3484d9c625SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3584d9c625SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3684d9c625SLionel Sambuc  * SUCH DAMAGE.
3784d9c625SLionel Sambuc  *
3884d9c625SLionel Sambuc  *	@(#)regfree.c	8.2 (Berkeley) 3/16/94
3984d9c625SLionel Sambuc  */
4084d9c625SLionel Sambuc 
41*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
42*0a6a1f1dSLionel Sambuc #if 0
4384d9c625SLionel Sambuc #if defined(LIBC_SCCS) && !defined(lint)
4484d9c625SLionel Sambuc static char sccsid[] = "@(#)regfree.c	8.2 (Berkeley) 3/16/94";
4584d9c625SLionel Sambuc #endif /* LIBC_SCCS and not lint */
46*0a6a1f1dSLionel Sambuc #else
47*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: regfree.c,v 1.5 2014/01/26 21:47:00 christos Exp $");
48*0a6a1f1dSLionel Sambuc #endif
4984d9c625SLionel Sambuc 
5084d9c625SLionel Sambuc #include <sys/types.h>
5184d9c625SLionel Sambuc #include <stdio.h>
5284d9c625SLionel Sambuc #include <stdlib.h>
5384d9c625SLionel Sambuc #include <regex.h>
5484d9c625SLionel Sambuc 
5584d9c625SLionel Sambuc #include "utils.h"
5684d9c625SLionel Sambuc #include "regex2.h"
5784d9c625SLionel Sambuc 
5884d9c625SLionel Sambuc /*
5984d9c625SLionel Sambuc  - regfree - free everything
6084d9c625SLionel Sambuc  = extern void regfree(regex_t *);
6184d9c625SLionel Sambuc  */
6284d9c625SLionel Sambuc void
regfree(regex_t * preg)6384d9c625SLionel Sambuc regfree(regex_t *preg)
6484d9c625SLionel Sambuc {
65*0a6a1f1dSLionel Sambuc 	struct re_guts *g;
6684d9c625SLionel Sambuc 
6784d9c625SLionel Sambuc 	if (preg->re_magic != MAGIC1)	/* oops */
6884d9c625SLionel Sambuc 		return;			/* nice to complain, but hard */
6984d9c625SLionel Sambuc 
7084d9c625SLionel Sambuc 	g = preg->re_g;
7184d9c625SLionel Sambuc 	if (g == NULL || g->magic != MAGIC2)	/* oops again */
7284d9c625SLionel Sambuc 		return;
7384d9c625SLionel Sambuc 	preg->re_magic = 0;		/* mark it invalid */
7484d9c625SLionel Sambuc 	g->magic = 0;			/* mark it invalid */
7584d9c625SLionel Sambuc 
7684d9c625SLionel Sambuc 	if (g->strip != NULL)
7784d9c625SLionel Sambuc 		free((char *)g->strip);
7884d9c625SLionel Sambuc 	if (g->stripdata != NULL)
7984d9c625SLionel Sambuc 		free((char *)g->stripdata);
8084d9c625SLionel Sambuc 	if (g->sets != NULL)
8184d9c625SLionel Sambuc 		free((char *)g->sets);
8284d9c625SLionel Sambuc 	if (g->setbits != NULL)
8384d9c625SLionel Sambuc 		free((char *)g->setbits);
8484d9c625SLionel Sambuc 	if (g->must != NULL)
8584d9c625SLionel Sambuc 		free(g->must);
8684d9c625SLionel Sambuc 	free((char *)g);
8784d9c625SLionel Sambuc }
88