diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 2562eb5416..286e983ae8 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -989,46 +989,62 @@ IsoLocaleName(const char *winlocname) { #ifdef _MSC_VER static char iso_lc_messages[32]; - _locale_t loct = NULL; + size_t rc = -1; + char* hyphen; if (pg_strcasecmp("c", winlocname) == 0 || pg_strcasecmp("posix", winlocname) == 0) { - strcpy(iso_lc_messages, "C"); - return iso_lc_messages; + return "C"; } +#if _WIN32_WINNT >= 0x0600 + WCHAR wc_locale_name[LOCALE_NAME_MAX_LENGTH]; + WCHAR buffer[LOCALE_NAME_MAX_LENGTH]; + + memset(wc_locale_name, 0, sizeof(wc_locale_name)); + memset(buffer, 0, sizeof(buffer)); + MultiByteToWideChar(CP_ACP, 0, winlocname, -1, wc_locale_name, + LOCALE_NAME_MAX_LENGTH); + if ((GetLocaleInfoEx(wc_locale_name, LOCALE_SNAME, + (LPWSTR)&buffer, LOCALE_NAME_MAX_LENGTH)) > 0) { + rc = wchar2char(iso_lc_messages, buffer, sizeof(iso_lc_messages), + NULL); + } +#else /* _WIN32_WINNT < 0x0600 */ + _locale_t loct; loct = _create_locale(LC_CTYPE, winlocname); if (loct != NULL) { - size_t rc; - char *hyphen; - /* Locale names use only ASCII, any conversion locale suffices. */ rc = wchar2char(iso_lc_messages, loct->locinfo->locale_name[LC_CTYPE], sizeof(iso_lc_messages), NULL); _free_locale(loct); - if (rc == -1 || rc == sizeof(iso_lc_messages)) - return NULL; - - /* - * Since the message catalogs sit on a case-insensitive filesystem, we - * need not standardize letter case here. So long as we do not ship - * message catalogs for which it would matter, we also need not - * translate the script/variant portion, e.g. uz-Cyrl-UZ to - * uz_UZ@cyrillic. Simply replace the hyphen with an underscore. - * - * Note that the locale name can be less-specific than the value we - * would derive under earlier Visual Studio releases. For example, - * French_France.1252 yields just "fr". This does not affect any of - * the country-specific message catalogs available as of this writing - * (pt_BR, zh_CN, zh_TW). - */ - hyphen = strchr(iso_lc_messages, '-'); - if (hyphen) - *hyphen = '_'; - return iso_lc_messages; } +#endif /* _WIN32_WINNT >= 0x0600 */ + else + return NULL; + + if (rc == -1 || rc == sizeof(iso_lc_messages)) + return NULL; + + /* + * Since the message catalogs sit on a case-insensitive filesystem, we + * need not standardize letter case here. So long as we do not ship + * message catalogs for which it would matter, we also need not + * translate the script/variant portion, e.g. uz-Cyrl-UZ to + * uz_UZ@cyrillic. Simply replace the hyphen with an underscore. + * + * Note that the locale name can be less-specific than the value we + * would derive under earlier Visual Studio releases. For example, + * French_France.1252 yields just "fr". This does not affect any of + * the country-specific message catalogs available as of this writing + * (pt_BR, zh_CN, zh_TW). + */ + hyphen = strchr(iso_lc_messages, '-'); + if (hyphen) + *hyphen = '_'; + return iso_lc_messages; #endif /* _MSC_VER */ return NULL; /* Not supported on this version of msvc/mingw */ }