1 /*
2 Copyright (c) 1996 - 2002 FreeBSD Project
3 Copyright (c) 1991, 1993
4 The Regents of the University of California. All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 4. Neither the name of the University nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 SUCH DAMAGE.
29 */
30 /*
31 FUNCTION
32 <<freelocale>>---free resources allocated for a locale object
33
34 INDEX
35 freelocale
36
37 INDEX
38 _freelocale_r
39
40 SYNOPSIS
41 #include <locale.h>
42 locale_t freelocale(locale_t <[locobj]>);
43
44 locale_t _freelocale_r(void *<[reent]>, locale_t <[locobj]>);
45
46 DESCRIPTION
47 The <<freelocale>> function shall cause the resources allocated for a
48 locale object returned by a call to the <<newlocale>> or <<duplocale>>
49 functions to be released.
50
51 The behavior is undefined if the <[locobj]> argument is the special locale
52 object LC_GLOBAL_LOCALE or is not a valid locale object handle.
53
54 Any use of a locale object that has been freed results in undefined
55 behavior.
56
57 RETURNS
58 None.
59
60 PORTABILITY
61 <<freelocale>> is POSIX-1.2008.
62 */
63
64 #define _DEFAULT_SOURCE
65 #include <newlib.h>
66 #include <stdlib.h>
67 #include "setlocale.h"
68
69 void
freelocale(struct __locale_t * locobj)70 freelocale (struct __locale_t *locobj)
71 {
72 (void) locobj;
73 /* Nothing to do on !_MB_CAPABLE targets. */
74 #ifdef _MB_CAPABLE
75 /* Sanity check. The "C" locale is static, don't try to free it. */
76 if (!locobj || locobj == __get_C_locale () || locobj == LC_GLOBAL_LOCALE)
77 return;
78 #ifdef __HAVE_LOCALE_INFO__
79 for (int i = 1; i < _LC_LAST; ++i)
80 if (locobj->lc_cat[i].buf)
81 {
82 free ((void *) locobj->lc_cat[i].ptr);
83 free (locobj->lc_cat[i].buf);
84 }
85 #endif /* __HAVE_LOCALE_INFO__ */
86 free (locobj);
87 #endif /* _MB_CAPABLE */
88 }
89