4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / lib / libc / regex / regfree.c
CommitLineData
93ea669f
KB
1/*-
2 * Copyright (c) 1992 Henry Spencer.
1d7941ec
KB
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
93ea669f
KB
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Henry Spencer of the University of Toronto.
8 *
9 * %sccs.include.redist.c%
10 *
1d7941ec 11 * @(#)regfree.c 8.1 (Berkeley) %G%
93ea669f
KB
12 */
13
14#if defined(LIBC_SCCS) && !defined(lint)
1d7941ec 15static char sccsid[] = "@(#)regfree.c 8.1 (Berkeley) %G%";
93ea669f
KB
16#endif /* LIBC_SCCS and not lint */
17
18#include <sys/types.h>
93ea669f
KB
19#include <stdio.h>
20#include <stdlib.h>
21#include <regex.h>
22
23#include "utils.h"
24#include "regex2.h"
25
26/*
27 - regfree - free everything
6175ca7c 28 = extern void regfree(regex_t *preg);
93ea669f
KB
29 */
30void
31regfree(preg)
32regex_t *preg;
33{
34 register struct re_guts *g;
35
36 if (preg->re_magic != MAGIC1) /* oops */
37 return; /* nice to complain, but hard */
38
39 g = preg->re_g;
40 if (g == NULL || g->magic != MAGIC2) /* oops again */
41 return;
42 preg->re_magic = 0; /* mark it invalid */
43 g->magic = 0; /* mark it invalid */
44
45 if (g->strip != NULL)
46 free((char *)g->strip);
47 if (g->sets != NULL)
48 free((char *)g->sets);
49 if (g->setbits != NULL)
50 free((char *)g->setbits);
51 if (g->must != NULL)
6175ca7c
KB
52 free(g->must);
53 free((char *)g);
93ea669f 54}