Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / locale / freelocale.c
blobf5d55f5e2acc7823566bf025d5e9803852156676
1 /*
2 FUNCTION
3 <<freelocale>>---free resources allocated for a locale object
5 INDEX
6 freelocale
8 INDEX
9 _freelocale_r
11 SYNOPSIS
12 #include <locale.h>
13 locale_t freelocale(locale_t <[locobj]>);
15 locale_t _freelocale_r(void *<[reent]>, locale_t <[locobj]>);
17 DESCRIPTION
18 The <<freelocale>> function shall cause the resources allocated for a
19 locale object returned by a call to the <<newlocale>> or <<duplocale>>
20 functions to be released.
22 The behavior is undefined if the <[locobj]> argument is the special locale
23 object LC_GLOBAL_LOCALE or is not a valid locale object handle.
25 Any use of a locale object that has been freed results in undefined
26 behavior.
28 RETURNS
29 None.
31 PORTABILITY
32 <<freelocale>> is POSIX-1.2008.
35 #include <newlib.h>
36 #include <reent.h>
37 #include <stdlib.h>
38 #include "setlocale.h"
40 void
41 _freelocale_r (struct _reent *p, struct __locale_t *locobj)
43 /* Nothing to do on !_MB_CAPABLE targets. */
44 #ifdef _MB_CAPABLE
45 /* Sanity check. The "C" locale is static, don't try to free it. */
46 if (!locobj || locobj == __get_C_locale () || locobj == LC_GLOBAL_LOCALE)
47 return;
48 #ifdef __HAVE_LOCALE_INFO__
49 for (int i = 1; i < _LC_LAST; ++i)
50 if (locobj->lc_cat[i].buf)
52 _free_r (p, (void *) locobj->lc_cat[i].ptr);
53 _free_r (p, locobj->lc_cat[i].buf);
55 #endif /* __HAVE_LOCALE_INFO__ */
56 _free_r (p, locobj);
57 #endif /* _MB_CAPABLE */
60 void
61 freelocale (struct __locale_t *locobj)
63 _freelocale_r (_REENT, locobj);