*** src/backend/utils/adt/pg_locale.c.orig Sun Nov 16 21:51:24 2008 --- src/backend/utils/adt/pg_locale.c Sun Nov 16 22:10:34 2008 *************** *** 54,59 **** --- 54,60 ---- #include "utils/memutils.h" #include "utils/pg_locale.h" + #include "mb/pg_wchar.h" #define MAX_L10N_DATA 80 *************** *** 451,456 **** --- 452,503 ---- CurrentLocaleConvValid = true; return &CurrentLocaleConv; } + + #ifdef WIN32 + /* + * strftime in Windows returns in CP_ACP encoding, but it could be + * different from SERVER_ENCODING. Especially, Windows Japanese edition + * requires conversions because it uses SJIS as CP_ACP, but we don't + * support SJIS as a server encoding. + */ + static size_t + strftime_win32(char *dst, size_t dstlen, const char *format, const struct tm *tm) + { + size_t len; + wchar_t wbuf[MAX_L10N_DATA]; + int encoding; + + len = strftime(dst, dstlen, format, tm); + encoding = GetDatabaseEncoding(); + if (encoding == PG_SQL_ASCII) + return len; + + len = MultiByteToWideChar(CP_ACP, 0, dst, len, wbuf, MAX_L10N_DATA); + if (len == 0) + ereport(ERROR, + (errmsg("could not convert string to wide character:error %lu", GetLastError()))); + len = WideCharToMultiByte(CP_UTF8, 0, wbuf, len, dst, dstlen, NULL, NULL); + if (len == 0) + ereport(ERROR, + (errmsg("could not convert wide character to UTF-8:error %lu", GetLastError()))); + + dst[len] = '\0'; + if (encoding != PG_UTF8) + { + char *convstr = pg_do_encoding_conversion(dst, len, PG_UTF8, encoding); + if (dst != convstr) + { + StrNCpy(dst, convstr, dstlen); + len = strlen(dst); + } + } + + return len; + } + + #define strftime(a,b,c,d) strftime_win32(a,b,c,d) + + #endif /* WIN32 */ /*