3 #include "locale_impl.h"
6 int __loc_is_allocated(locale_t loc
)
8 return loc
&& loc
!= C_LOCALE
&& loc
!= UTF8_LOCALE
;
11 locale_t
__newlocale(int mask
, const char *name
, locale_t loc
)
14 struct __locale_struct tmp
;
15 const struct __locale_map
*lm
;
17 /* For locales with allocated storage, modify in-place. */
18 if (__loc_is_allocated(loc
)) {
19 for (i
=0; i
<LC_ALL
; i
++)
21 loc
->cat
[i
] = __get_locale(i
, name
);
25 /* Otherwise, build a temporary locale object, which will only
26 * be instantiated in allocated storage if it does not match
27 * one of the built-in static locales. This makes the common
28 * usage case for newlocale, getting a C locale with predictable
29 * behavior, very fast, and more importantly, fail-safe. */
30 for (j
=i
=0; i
<LC_ALL
; i
++) {
31 if (loc
&& !(mask
& (1<<i
)))
34 lm
= __get_locale(i
, mask
& (1<<i
) ? name
: "");
41 if (j
==1 && tmp
.cat
[LC_CTYPE
]==&__c_dot_utf8
)
44 if ((loc
= malloc(sizeof *loc
))) *loc
= tmp
;
49 weak_alias(__newlocale
, newlocale
);