[444] | 1 | /* |
---|
| 2 | FUNCTION |
---|
| 3 | <<freelocale>>---free resources allocated for a locale object |
---|
| 4 | |
---|
| 5 | INDEX |
---|
| 6 | freelocale |
---|
| 7 | |
---|
| 8 | INDEX |
---|
| 9 | _freelocale_r |
---|
| 10 | |
---|
| 11 | SYNOPSIS |
---|
| 12 | #include <locale.h> |
---|
| 13 | locale_t freelocale(locale_t <[locobj]>); |
---|
| 14 | |
---|
| 15 | locale_t _freelocale_r(void *<[reent]>, locale_t <[locobj]>); |
---|
| 16 | |
---|
| 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. |
---|
| 21 | |
---|
| 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. |
---|
| 24 | |
---|
| 25 | Any use of a locale object that has been freed results in undefined |
---|
| 26 | behavior. |
---|
| 27 | |
---|
| 28 | RETURNS |
---|
| 29 | None. |
---|
| 30 | |
---|
| 31 | PORTABILITY |
---|
| 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 | |
---|
| 40 | void |
---|
| 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 | |
---|
| 60 | void |
---|
| 61 | freelocale (struct __locale_t *locobj) |
---|
| 62 | { |
---|
| 63 | _freelocale_r (_REENT, locobj); |
---|
| 64 | } |
---|