diff options
Diffstat (limited to 'src/locale')
-rw-r--r-- | src/locale/dcngettext.c | 3 | ||||
-rw-r--r-- | src/locale/duplocale.c | 5 | ||||
-rw-r--r-- | src/locale/freelocale.c | 5 | ||||
-rw-r--r-- | src/locale/iconv.c | 9 | ||||
-rw-r--r-- | src/locale/locale_map.c | 13 | ||||
-rw-r--r-- | src/locale/newlocale.c | 32 | ||||
-rw-r--r-- | src/locale/setlocale.c | 11 | ||||
-rw-r--r-- | src/locale/strtod_l.c | 22 |
8 files changed, 71 insertions, 29 deletions
diff --git a/src/locale/dcngettext.c b/src/locale/dcngettext.c index d1e6c6d1..0b53286d 100644 --- a/src/locale/dcngettext.c +++ b/src/locale/dcngettext.c @@ -132,6 +132,9 @@ char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, struct binding *q; int old_errno = errno; + /* match gnu gettext behaviour */ + if (!msgid1) goto notrans; + if ((unsigned)category >= LC_ALL) goto notrans; if (!domainname) domainname = __gettextdomain(); diff --git a/src/locale/duplocale.c b/src/locale/duplocale.c index 030b64cb..5ce33ae6 100644 --- a/src/locale/duplocale.c +++ b/src/locale/duplocale.c @@ -3,6 +3,11 @@ #include "locale_impl.h" #include "libc.h" +#define malloc __libc_malloc +#define calloc undef +#define realloc undef +#define free undef + locale_t __duplocale(locale_t old) { locale_t new = malloc(sizeof *new); diff --git a/src/locale/freelocale.c b/src/locale/freelocale.c index 802b8bfe..385d1206 100644 --- a/src/locale/freelocale.c +++ b/src/locale/freelocale.c @@ -1,6 +1,11 @@ #include <stdlib.h> #include "locale_impl.h" +#define malloc undef +#define calloc undef +#define realloc undef +#define free __libc_free + void freelocale(locale_t l) { if (__loc_is_allocated(l)) free(l); diff --git a/src/locale/iconv.c b/src/locale/iconv.c index 3047c27b..7fb2e1ef 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -49,10 +49,10 @@ static const unsigned char charmaps[] = "ucs4\0utf32\0\0\313" "ucs2\0\0\314" "eucjp\0\0\320" -"shiftjis\0sjis\0\0\321" +"shiftjis\0sjis\0cp932\0\0\321" "iso2022jp\0\0\322" "gb18030\0\0\330" -"gbk\0\0\331" +"gbk\0cp936\0windows936\0\0\331" "gb2312\0\0\332" "big5\0bigfive\0cp950\0big5hkscs\0\0\340" "euckr\0ksc5601\0ksx1001\0cp949\0\0\350" @@ -340,6 +340,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri c++; d -= 159; } + if (c>=84) goto ilseq; c = jis0208[c][d]; if (!c) goto ilseq; break; @@ -403,6 +404,10 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri if (c < 128) break; if (c < 0xa1) goto ilseq; case GBK: + if (c == 128) { + c = 0x20ac; + break; + } case GB18030: if (c < 128) break; c -= 0x81; diff --git a/src/locale/locale_map.c b/src/locale/locale_map.c index fa51f2e3..da61f7fc 100644 --- a/src/locale/locale_map.c +++ b/src/locale/locale_map.c @@ -28,8 +28,8 @@ static const char envvars[][12] = { "LC_MESSAGES", }; -static volatile int lock[1]; -volatile int *const __locale_lockptr = lock; +volatile int __locale_lock[1]; +volatile int *const __locale_lockptr = __locale_lock; const struct __locale_map *__get_locale(int cat, const char *val) { @@ -63,14 +63,6 @@ const struct __locale_map *__get_locale(int cat, const char *val) for (p=loc_head; p; p=p->next) if (!strcmp(val, p->name)) return p; - LOCK(lock); - - for (p=loc_head; p; p=p->next) - if (!strcmp(val, p->name)) { - UNLOCK(lock); - return p; - } - if (!libc.secure) path = getenv("MUSL_LOCPATH"); /* FIXME: add a default path? */ @@ -117,6 +109,5 @@ const struct __locale_map *__get_locale(int cat, const char *val) * requested name was "C" or "POSIX". */ if (!new && cat == LC_CTYPE) new = (void *)&__c_dot_utf8; - UNLOCK(lock); return new; } diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c index d20a8489..9ac3cd38 100644 --- a/src/locale/newlocale.c +++ b/src/locale/newlocale.c @@ -2,16 +2,15 @@ #include <string.h> #include <pthread.h> #include "locale_impl.h" +#include "lock.h" -static pthread_once_t default_locale_once; -static struct __locale_struct default_locale, default_ctype_locale; +#define malloc __libc_malloc +#define calloc undef +#define realloc undef +#define free undef -static void default_locale_init(void) -{ - for (int i=0; i<LC_ALL; i++) - default_locale.cat[i] = __get_locale(i, ""); - default_ctype_locale.cat[LC_CTYPE] = default_locale.cat[LC_CTYPE]; -} +static int default_locale_init_done; +static struct __locale_struct default_locale, default_ctype_locale; int __loc_is_allocated(locale_t loc) { @@ -19,7 +18,7 @@ int __loc_is_allocated(locale_t loc) && loc != &default_locale && loc != &default_ctype_locale; } -locale_t __newlocale(int mask, const char *name, locale_t loc) +static locale_t do_newlocale(int mask, const char *name, locale_t loc) { struct __locale_struct tmp; @@ -44,7 +43,12 @@ locale_t __newlocale(int mask, const char *name, locale_t loc) /* And provide builtins for the initial default locale, and a * variant of the C locale honoring the default locale's encoding. */ - pthread_once(&default_locale_once, default_locale_init); + if (!default_locale_init_done) { + for (int i=0; i<LC_ALL; i++) + default_locale.cat[i] = __get_locale(i, ""); + default_ctype_locale.cat[LC_CTYPE] = default_locale.cat[LC_CTYPE]; + default_locale_init_done = 1; + } if (!memcmp(&tmp, &default_locale, sizeof tmp)) return &default_locale; if (!memcmp(&tmp, &default_ctype_locale, sizeof tmp)) return &default_ctype_locale; @@ -55,4 +59,12 @@ locale_t __newlocale(int mask, const char *name, locale_t loc) return loc; } +locale_t __newlocale(int mask, const char *name, locale_t loc) +{ + LOCK(__locale_lock); + loc = do_newlocale(mask, name, loc); + UNLOCK(__locale_lock); + return loc; +} + weak_alias(__newlocale, newlocale); diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c index 2bc7b500..360c4437 100644 --- a/src/locale/setlocale.c +++ b/src/locale/setlocale.c @@ -9,12 +9,11 @@ static char buf[LC_ALL*(LOCALE_NAME_MAX+1)]; char *setlocale(int cat, const char *name) { - static volatile int lock[1]; const struct __locale_map *lm; if ((unsigned)cat > LC_ALL) return 0; - LOCK(lock); + LOCK(__locale_lock); /* For LC_ALL, setlocale is required to return a string which * encodes the current setting for all categories. The format of @@ -36,7 +35,7 @@ char *setlocale(int cat, const char *name) } lm = __get_locale(i, part); if (lm == LOC_MAP_FAILED) { - UNLOCK(lock); + UNLOCK(__locale_lock); return 0; } tmp_locale.cat[i] = lm; @@ -57,14 +56,14 @@ char *setlocale(int cat, const char *name) s += l+1; } *--s = 0; - UNLOCK(lock); + UNLOCK(__locale_lock); return same==LC_ALL ? (char *)part : buf; } if (name) { lm = __get_locale(cat, name); if (lm == LOC_MAP_FAILED) { - UNLOCK(lock); + UNLOCK(__locale_lock); return 0; } libc.global_locale.cat[cat] = lm; @@ -73,7 +72,7 @@ char *setlocale(int cat, const char *name) } char *ret = lm ? (char *)lm->name : "C"; - UNLOCK(lock); + UNLOCK(__locale_lock); return ret; } diff --git a/src/locale/strtod_l.c b/src/locale/strtod_l.c new file mode 100644 index 00000000..574ba148 --- /dev/null +++ b/src/locale/strtod_l.c @@ -0,0 +1,22 @@ +#define _GNU_SOURCE +#include <stdlib.h> +#include <locale.h> + +float strtof_l(const char *restrict s, char **restrict p, locale_t l) +{ + return strtof(s, p); +} + +double strtod_l(const char *restrict s, char **restrict p, locale_t l) +{ + return strtod(s, p); +} + +long double strtold_l(const char *restrict s, char **restrict p, locale_t l) +{ + return strtold(s, p); +} + +weak_alias(strtof_l, __strtof_l); +weak_alias(strtod_l, __strtod_l); +weak_alias(strtold_l, __strtold_l); |