source: trunk/libs/newlib/src/newlib/libc/locale/freelocale.c

Last change on this file was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.4 KB
Line 
1/*
2FUNCTION
3        <<freelocale>>---free resources allocated for a locale object
4
5INDEX
6        freelocale
7
8INDEX
9        _freelocale_r
10
11SYNOPSIS
12        #include <locale.h>
13        locale_t freelocale(locale_t <[locobj]>);
14
15        locale_t _freelocale_r(void *<[reent]>, locale_t <[locobj]>);
16
17DESCRIPTION
18The <<freelocale>> function shall cause the resources allocated for a
19locale object returned by a call to the <<newlocale>> or <<duplocale>>
20functions to be released.
21
22The behavior is undefined if the <[locobj]> argument is the special locale
23object LC_GLOBAL_LOCALE or is not a valid locale object handle.
24
25Any use of a locale object that has been freed results in undefined
26behavior.
27
28RETURNS
29None.
30
31PORTABILITY
32<<freelocale>> is POSIX-1.2008.
33*/
34
35#include <newlib.h>
36#include <reent.h>
37#include <stdlib.h>
38#include "setlocale.h"
39
40void
41_freelocale_r (struct _reent *p, struct __locale_t *locobj)
42{
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)
51      {
52        _free_r (p, (void *) locobj->lc_cat[i].ptr);
53        _free_r (p, locobj->lc_cat[i].buf);
54      }
55#endif /* __HAVE_LOCALE_INFO__ */
56  _free_r (p, locobj);
57#endif /* _MB_CAPABLE */
58}
59
60void
61freelocale (struct __locale_t *locobj)
62{
63  _freelocale_r (_REENT, locobj);
64}
Note: See TracBrowser for help on using the repository browser.