#include #include #include "locale_impl.h" #include "libc.h" extern const struct __locale_map __c_dot_utf8; static const struct __locale_struct c_locale = { 0 }; static const struct __locale_struct c_dot_utf8_locale = { .cat[LC_CTYPE] = &__c_dot_utf8 }; int __loc_is_allocated(locale_t loc) { return loc && loc != &c_locale && loc != &c_dot_utf8_locale; } locale_t __newlocale(int mask, const char *name, locale_t loc) { int i, j; struct __locale_struct tmp; const struct __locale_map *lm; /* For locales with allocated storage, modify in-place. */ if (__loc_is_allocated(loc)) { for (i=0; icat[i] = __get_locale(i, name); return loc; } /* Otherwise, build a temporary locale object, which will only * be instantiated in allocated storage if it does not match * one of the built-in static locales. This makes the common * usage case for newlocale, getting a C locale with predictable * behavior, very fast, and more importantly, fail-safe. */ for (j=i=0; icat[i]; else lm = __get_locale(i, mask & (1<