diff options
Diffstat (limited to 'usr/src')
| -rw-r--r-- | usr/src/lib/libc/port/locale/localeimpl.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/usr/src/lib/libc/port/locale/localeimpl.c b/usr/src/lib/libc/port/locale/localeimpl.c index 24c03d558a..945fce2143 100644 --- a/usr/src/lib/libc/port/locale/localeimpl.c +++ b/usr/src/lib/libc/port/locale/localeimpl.c @@ -288,6 +288,19 @@ locdata_get_cache(int category, const char *locname) return (loc); } +/* Charmap aliases, mostly found in Linux */ +static const struct { + const char *alias; + const char *name; +} cmalias[] = { + { "utf8", "UTF-8" }, + { "iso88591", "ISO8859-1" }, + { "iso885915", "ISO8859-15" }, + { "gb18030", "GB18030" }, + { "koi8r", "KOI8-R" }, + { NULL, NULL } +}; + /* * Routine to get the locdata for a given category and locale. * This includes retrieving it from cache, retrieving it from @@ -297,9 +310,11 @@ static struct locdata * locdata_get(int category, const char *locname) { char scratch[ENCODING_LEN + 1]; - char *slash; + char scratch2[ENCODING_LEN + 1]; + char *slash, *cm; int cnt; int len; + int i; if (locname == NULL || *locname == 0) { locname = get_locale_env(category); @@ -329,6 +344,21 @@ locdata_get(int category, const char *locname) if ((strcmp(locname, "C") == 0) || (strcmp(locname, "POSIX") == 0)) return (posix_locale.locdata[category]); + /* Handle charmap aliases */ + for (i = 0; cmalias[i].alias != NULL; i++) { + if ((cm = strstr(locname, cmalias[i].alias)) != NULL && + strlen(cm) == strlen(cmalias[i].alias)) { + len = cm - locname + 1; + if (len + strlen(cmalias[i].name) >= sizeof (scratch2)) + break; + (void) strlcpy(scratch2, locname, len); + (void) strlcat(scratch2, cmalias[i].name, + sizeof (scratch2)); + locname = scratch2; + break; + } + } + if ((strcmp(locname, "C.UTF-8") == 0) && (category != LC_CTYPE)) return (&cutf_locdata[category]); |
