xref: /titanic_52/usr/src/lib/libc/port/locale/regfree.c (revision 6b5e5868e7ebf1aff3a5abd7d0c4ef0e5fbf3648)
14297a3b0SGarrett D'Amore /*
2*6b5e5868SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
34297a3b0SGarrett D'Amore  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
44297a3b0SGarrett D'Amore  * Copyright (c) 1992, 1993, 1994
54297a3b0SGarrett D'Amore  *	The Regents of the University of California.  All rights reserved.
64297a3b0SGarrett D'Amore  *
74297a3b0SGarrett D'Amore  * This code is derived from software contributed to Berkeley by
84297a3b0SGarrett D'Amore  * Henry Spencer.
94297a3b0SGarrett D'Amore  *
104297a3b0SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
114297a3b0SGarrett D'Amore  * modification, are permitted provided that the following conditions
124297a3b0SGarrett D'Amore  * are met:
134297a3b0SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright
144297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer.
154297a3b0SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright
164297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer in the
174297a3b0SGarrett D'Amore  *    documentation and/or other materials provided with the distribution.
184297a3b0SGarrett D'Amore  * 4. Neither the name of the University nor the names of its contributors
194297a3b0SGarrett D'Amore  *    may be used to endorse or promote products derived from this software
204297a3b0SGarrett D'Amore  *    without specific prior written permission.
214297a3b0SGarrett D'Amore  *
224297a3b0SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
234297a3b0SGarrett D'Amore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
244297a3b0SGarrett D'Amore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
254297a3b0SGarrett D'Amore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
264297a3b0SGarrett D'Amore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
274297a3b0SGarrett D'Amore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
284297a3b0SGarrett D'Amore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
294297a3b0SGarrett D'Amore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
304297a3b0SGarrett D'Amore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
314297a3b0SGarrett D'Amore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
324297a3b0SGarrett D'Amore  * SUCH DAMAGE.
334297a3b0SGarrett D'Amore  */
344297a3b0SGarrett D'Amore 
354297a3b0SGarrett D'Amore #include "lint.h"
364297a3b0SGarrett D'Amore #include "file64.h"
374297a3b0SGarrett D'Amore #include <sys/types.h>
384297a3b0SGarrett D'Amore #include <stdio.h>
394297a3b0SGarrett D'Amore #include <stdlib.h>
404297a3b0SGarrett D'Amore #include <limits.h>
414297a3b0SGarrett D'Amore #include <regex.h>
424297a3b0SGarrett D'Amore #include <wchar.h>
434297a3b0SGarrett D'Amore #include <wctype.h>
444297a3b0SGarrett D'Amore 
454297a3b0SGarrett D'Amore #include "utils.h"
464297a3b0SGarrett D'Amore #include "regex2.h"
474297a3b0SGarrett D'Amore 
484297a3b0SGarrett D'Amore /*
494297a3b0SGarrett D'Amore  * regfree - free everything
504297a3b0SGarrett D'Amore  */
514297a3b0SGarrett D'Amore void
524297a3b0SGarrett D'Amore regfree(regex_t *preg)
534297a3b0SGarrett D'Amore {
544297a3b0SGarrett D'Amore 	struct re_guts *g;
554297a3b0SGarrett D'Amore 	int i;
564297a3b0SGarrett D'Amore 
574297a3b0SGarrett D'Amore #ifdef	__lint
584297a3b0SGarrett D'Amore 	/* shut up lint! */
594297a3b0SGarrett D'Amore 	CHIN(NULL, 0);
604297a3b0SGarrett D'Amore #endif
614297a3b0SGarrett D'Amore 
624297a3b0SGarrett D'Amore 	if (preg->re_magic != MAGIC1)	/* oops */
634297a3b0SGarrett D'Amore 		return;			/* nice to complain, but hard */
644297a3b0SGarrett D'Amore 
654297a3b0SGarrett D'Amore 	g = preg->re_g;
664297a3b0SGarrett D'Amore 	if (g == NULL || g->magic != MAGIC2)	/* oops again */
674297a3b0SGarrett D'Amore 		return;
684297a3b0SGarrett D'Amore 	preg->re_magic = 0;		/* mark it invalid */
694297a3b0SGarrett D'Amore 	g->magic = 0;			/* mark it invalid */
704297a3b0SGarrett D'Amore 
714297a3b0SGarrett D'Amore 	if (g->strip != NULL)
724297a3b0SGarrett D'Amore 		free((char *)g->strip);
734297a3b0SGarrett D'Amore 	if (g->sets != NULL) {
744297a3b0SGarrett D'Amore 		for (i = 0; i < g->ncsets; i++) {
754297a3b0SGarrett D'Amore 			free(g->sets[i].ranges);
764297a3b0SGarrett D'Amore 			free(g->sets[i].wides);
774297a3b0SGarrett D'Amore 			free(g->sets[i].types);
784297a3b0SGarrett D'Amore 		}
794297a3b0SGarrett D'Amore 		free((char *)g->sets);
804297a3b0SGarrett D'Amore 	}
814297a3b0SGarrett D'Amore 	if (g->must != NULL)
824297a3b0SGarrett D'Amore 		free(g->must);
834297a3b0SGarrett D'Amore 	if (g->charjump != NULL)
844297a3b0SGarrett D'Amore 		free(&g->charjump[CHAR_MIN]);
854297a3b0SGarrett D'Amore 	if (g->matchjump != NULL)
864297a3b0SGarrett D'Amore 		free(g->matchjump);
874297a3b0SGarrett D'Amore 	free((char *)g);
884297a3b0SGarrett D'Amore }
89