X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Flocale%2Fnewlocale.c;h=8fb006a7fcdb934ec7031942f5fa1cb6eda6888c;hb=7eda27d025d6d52f855588590366c83d737eb727;hp=447c8fc20262420510135d7c26081acb4b86d638;hpb=4350935ca4521b647472b8c18053325e07541ba1;p=musl diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c index 447c8fc2..8fb006a7 100644 --- a/src/locale/newlocale.c +++ b/src/locale/newlocale.c @@ -1,14 +1,48 @@ #include #include #include "locale_impl.h" -#include "libc.h" -locale_t newlocale(int mask, const char *name, locale_t base) +int __loc_is_allocated(locale_t loc) { - if (*name && strcmp(name, "C") && strcmp(name, "POSIX")) - return 0; - if (!base) base = calloc(1, sizeof *base); - return base; + return loc && loc != C_LOCALE && loc != UTF8_LOCALE; } -weak_alias(newlocale, __newlocale); +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<