diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 403adb0..23bf991 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -2040,6 +2040,28 @@ check_locale_name(int category, const char *locale, char **canonname) /* set the locale with setlocale, to see if it accepts it. */ res = setlocale(category, locale); +#if defined(WIN32) && _WIN32_WINNT >= 0x0600 + { + wchar_t localename[LOCALE_NAME_MAX_LENGTH]; + char localebuf[LOCALE_NAME_MAX_LENGTH]; + LCID lcid; + char *hyphen; + + if (MultiByteToWideChar(CP_ACP, 0, res, -1, localename, + LOCALE_NAME_MAX_LENGTH) && + GetLocaleInfoEx(localename, LOCALE_RETURN_NUMBER | LOCALE_ILANGUAGE, + (LPWSTR)&lcid, sizeof(lcid)) && + LCIDToLocaleName(lcid, localename, LOCALE_NAME_MAX_LENGTH, 0) && + WideCharToMultiByte(CP_ACP, 0, localename, -1, localebuf, + LOCALE_NAME_MAX_LENGTH, NULL, NULL)) + { + hyphen = strchr(localebuf, '-'); + if (hyphen) + *hyphen = '_'; + res = pg_strdup(localebuf); + } + } +#endif /* save canonical name if requested. */ if (res && canonname)