#include #include #include #include "locale_impl.h" #include "lock.h" #define malloc __libc_malloc #define calloc undef #define realloc undef #define free undef static int default_locale_init_done; static struct __locale_struct default_locale, default_ctype_locale; int __loc_is_allocated(locale_t loc) { return loc && loc != C_LOCALE && loc != UTF8_LOCALE && loc != &default_locale && loc != &default_ctype_locale; } static locale_t do_newlocale(int mask, const char *name, locale_t loc) { struct __locale_struct tmp; for (int i=0; icat[i] : __get_locale(i, (mask & (1<flag == INVALID) return 0; } /* For locales with allocated storage, modify in-place. */ if (__loc_is_allocated(loc)) { *loc = tmp; return loc; } /* Otherwise, first see if we can use one of the builtin locales. * This makes the common usage case for newlocale, getting a C locale * with predictable behavior, very fast, and more importantly, fail-safe. */ if (!memcmp(&tmp, C_LOCALE, sizeof tmp)) return C_LOCALE; if (!memcmp(&tmp, UTF8_LOCALE, sizeof tmp)) return UTF8_LOCALE; /* And provide builtins for the initial default locale, and a * variant of the C locale honoring the default locale's encoding. */ if (!default_locale_init_done) { for (int i=0; i