diff options
author | Yuri Pankov <yuri.pankov@nexenta.com> | 2019-09-11 03:04:52 +0300 |
---|---|---|
committer | Dan McDonald <danmcd@joyent.com> | 2019-09-19 21:06:11 -0400 |
commit | 13027a8e96cb0ef5c5e3dbe2594f7a17b73a95b5 (patch) | |
tree | 8bad1baf6a0dc6967a693b37fe8f479c6235bfe9 | |
parent | e75b2cb046700ccab0100afdcd81f2b860fcca87 (diff) | |
download | illumos-joyent-13027a8e96cb0ef5c5e3dbe2594f7a17b73a95b5.tar.gz |
11615 should handle locale charmap aliases
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Dan McDonald <danmcd@joyent.com>
-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]); |