diff options
author | Rich Felker <dalias@aerifal.cx> | 2014-07-24 03:23:11 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2014-07-24 03:23:11 -0400 |
commit | 6cb4f91db7a5dc3bca63037ddc5f998a08dc3fb0 (patch) | |
tree | 2a347ad0a3c5240c77d61ad8d078ed9a77ff22bb /src/locale/setlocale.c | |
parent | 674e28af2deaa3ef2b71af18f7a18af22467d5ef (diff) | |
download | musl-6cb4f91db7a5dc3bca63037ddc5f998a08dc3fb0.tar.gz musl-6cb4f91db7a5dc3bca63037ddc5f998a08dc3fb0.tar.xz musl-6cb4f91db7a5dc3bca63037ddc5f998a08dc3fb0.zip |
implement locale file loading and state for remaining locale categories
there is still no code which actually uses the loaded locale files, so the main observable effect of this commit is that calls to setlocale store and give back the names of the selected locales for the remaining categories (LC_TIME, LC_COLLATE, LC_MONETARY) if a locale file by the requested name could be loaded.
Diffstat (limited to 'src/locale/setlocale.c')
-rw-r--r-- | src/locale/setlocale.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c index cbc0b551..8ea389a3 100644 --- a/src/locale/setlocale.c +++ b/src/locale/setlocale.c @@ -9,6 +9,9 @@ static char buf[2+4*(LOCALE_NAME_MAX+1)]; char *setlocale(int cat, const char *name) { + struct __locale_map *lm; + int i, j; + if (!libc.global_locale.messages_name) { libc.global_locale.messages_name = buf + 2 + 3*(LOCALE_NAME_MAX+1); @@ -24,7 +27,6 @@ char *setlocale(int cat, const char *name) if (cat == LC_ALL) { if (name) { char part[LOCALE_NAME_MAX+1]; - int i, j; if (name[0] && name[1]==';' && strlen(name) > 2 + 3*(LOCALE_NAME_MAX+1)) { part[0] = name[0]; @@ -45,6 +47,11 @@ char *setlocale(int cat, const char *name) } memset(buf, ';', 2 + 3*(LOCALE_NAME_MAX+1)); buf[0] = libc.global_locale.ctype_utf8 ? 'U' : 'C'; + for (i=LC_TIME; i<LC_MESSAGES; i++) { + lm = libc.global_locale.cat[i-2]; + if (lm) memcpy(buf + 2 + (i-2)*(LOCALE_NAME_MAX+1), + lm->name, strlen(lm->name)); + } return buf; } @@ -58,10 +65,13 @@ char *setlocale(int cat, const char *name) switch (cat) { case LC_CTYPE: return libc.global_locale.ctype_utf8 ? "C.UTF-8" : "C"; + case LC_NUMERIC: + return "C"; case LC_MESSAGES: return libc.global_locale.messages_name[0] ? libc.global_locale.messages_name : "C"; default: - return "C"; + lm = libc.global_locale.cat[cat-2]; + return lm ? lm->name : "C"; } } |