diff -cpr HEAD/src/backend/storage/file/fd.c GetPlatformEncoding/src/backend/storage/file/fd.c *** HEAD/src/backend/storage/file/fd.c Thu Mar 5 13:14:27 2009 --- GetPlatformEncoding/src/backend/storage/file/fd.c Mon Apr 13 18:45:06 2009 *************** *** 49,54 **** --- 49,55 ---- #include /* for getrlimit */ #endif + #include "mb/pg_wchar.h" #include "miscadmin.h" #include "access/xact.h" #include "catalog/pg_tablespace.h" *************** static File OpenTemporaryFileInTablespac *** 247,252 **** --- 248,254 ---- static void AtProcExit_Files(int code, Datum arg); static void CleanupTempFiles(bool isProcExit); static void RemovePgTempFilesInDir(const char *tmpdirname); + static char *GetPlatformPath(const char *path); /* *************** int *** 494,505 **** BasicOpenFile(FileName fileName, int fileFlags, int fileMode) { int fd; tryAgain: ! fd = open(fileName, fileFlags, fileMode); if (fd >= 0) return fd; /* success! */ if (errno == EMFILE || errno == ENFILE) { --- 496,514 ---- BasicOpenFile(FileName fileName, int fileFlags, int fileMode) { int fd; + char *path; + + path = GetPlatformPath(fileName); tryAgain: ! fd = open(path, fileFlags, fileMode); if (fd >= 0) + { + if (path != fileName) + pfree(path); return fd; /* success! */ + } if (errno == EMFILE || errno == ENFILE) { *************** tryAgain: *** 514,519 **** --- 523,530 ---- errno = save_errno; } + if (path != fileName) + pfree(path); return -1; /* failure */ } *************** FILE * *** 1336,1345 **** --- 1347,1359 ---- AllocateFile(const char *name, const char *mode) { FILE *file; + char *path; DO_DB(elog(LOG, "AllocateFile: Allocated %d (%s)", numAllocatedDescs, name)); + path = GetPlatformPath(name); + /* * The test against MAX_ALLOCATED_DESCS prevents us from overflowing * allocatedFiles[]; the test against max_safe_fds prevents AllocateFile *************** AllocateFile(const char *name, const cha *** 1351,1357 **** elog(ERROR, "too many private files demanded"); TryAgain: ! if ((file = fopen(name, mode)) != NULL) { AllocateDesc *desc = &allocatedDescs[numAllocatedDescs]; --- 1365,1371 ---- elog(ERROR, "too many private files demanded"); TryAgain: ! if ((file = fopen(path, mode)) != NULL) { AllocateDesc *desc = &allocatedDescs[numAllocatedDescs]; *************** TryAgain: *** 1359,1364 **** --- 1373,1380 ---- desc->desc.file = file; desc->create_subid = GetCurrentSubTransactionId(); numAllocatedDescs++; + if (path != name) + pfree(path); return desc->desc.file; } *************** TryAgain: *** 1375,1380 **** --- 1391,1398 ---- errno = save_errno; } + if (path != name) + pfree(path); return NULL; } *************** RemovePgTempFilesInDir(const char *tmpdi *** 1875,1877 **** --- 1893,1905 ---- FreeDir(temp_dir); } + + static char * + GetPlatformPath(const char *path) + { + if (is_absolute_path(path)) + return (char *) pg_do_encoding_conversion((unsigned char *) path, + strlen(path), GetDatabaseEncoding(), GetPlatformEncoding()); + else + return (char *) path; + } diff -cpr HEAD/src/backend/utils/mb/mbutils.c GetPlatformEncoding/src/backend/utils/mb/mbutils.c *** HEAD/src/backend/utils/mb/mbutils.c Thu Apr 9 11:56:48 2009 --- GetPlatformEncoding/src/backend/utils/mb/mbutils.c Mon Apr 13 18:41:58 2009 *************** pg_client_encoding(PG_FUNCTION_ARGS) *** 1009,1011 **** --- 1009,1091 ---- Assert(ClientEncoding); return DirectFunctionCall1(namein, CStringGetDatum(ClientEncoding->name)); } + + #ifdef WIN32 + + struct codepage_to_encoding + { + UINT codepage; + enum pg_enc encoding; + }; + + static const struct codepage_to_encoding codepage2encoding[] = + { + {866, PG_WIN866}, + {874, PG_WIN874}, + {932, PG_SJIS}, + {936, PG_GBK}, + {950, PG_BIG5}, + {1250, PG_WIN1250}, + {1251, PG_WIN1251}, + {1252, PG_WIN1252}, + {1253, PG_WIN1253}, + {1254, PG_WIN1254}, + {1255, PG_WIN1255}, + {1256, PG_WIN1256}, + {1257, PG_WIN1257}, + {1258, PG_WIN1258}, + {1361, PG_JOHAB}, + {20866, PG_KOI8R}, + {20932, PG_EUC_JP}, + {20936, PG_EUC_CN}, + {21866, PG_KOI8U}, + {28591, PG_LATIN1}, + {28592, PG_LATIN2}, + {28593, PG_LATIN3}, + {28594, PG_LATIN4}, + {28595, PG_ISO_8859_5}, + {28596, PG_ISO_8859_6}, + {28597, PG_ISO_8859_7}, + {28598, PG_ISO_8859_8}, + {28599, PG_LATIN5}, + {28605, PG_LATIN9}, + {51949, PG_EUC_KR}, /* or 20949 ? */ + {54936, PG_GB18030}, + {65001, PG_UTF8} + }; + + static int + compare_codepage(const void *v1, const void *v2) + { + UINT cp1 = ((const struct codepage_to_encoding *) v1)->codepage; + UINT cp2 = ((const struct codepage_to_encoding *) v2)->codepage; + + if (cp1 < cp2) + return -1; + else if (cp1 > cp2) + return +1; + else + return 0; + } + + int + GetPlatformEncoding(void) + { + struct codepage_to_encoding key; + const struct codepage_to_encoding *found; + + key.codepage = GetACP(); + found = bsearch(&key, codepage2encoding, lengthof(codepage2encoding), + sizeof(key), compare_codepage); + return found ? found->encoding : PG_SQL_ASCII; + } + + #else + + int + GetPlatformEncoding(void) + { + return pg_get_encoding_from_locale(""); + } + + #endif diff -cpr HEAD/src/include/mb/pg_wchar.h GetPlatformEncoding/src/include/mb/pg_wchar.h *** HEAD/src/include/mb/pg_wchar.h Thu Apr 9 11:56:48 2009 --- GetPlatformEncoding/src/include/mb/pg_wchar.h Mon Apr 13 18:41:58 2009 *************** extern void SetDatabaseEncoding(int enco *** 392,397 **** --- 392,398 ---- extern int GetDatabaseEncoding(void); extern const char *GetDatabaseEncodingName(void); extern void pg_bind_textdomain_codeset(const char *domainname); + extern int GetPlatformEncoding(void); extern int pg_valid_client_encoding(const char *name); extern int pg_valid_server_encoding(const char *name); diff -cpr HEAD/src/port/chklocale.c GetPlatformEncoding/src/port/chklocale.c *** HEAD/src/port/chklocale.c Fri Feb 13 09:58:01 2009 --- GetPlatformEncoding/src/port/chklocale.c Mon Apr 13 19:00:20 2009 *************** static const struct encoding_match encod *** 73,78 **** --- 73,79 ---- {PG_UTF8, "UTF-8"}, {PG_UTF8, "utf8"}, {PG_UTF8, "CP65001"}, + {PG_UTF8, "ANSI_X3.4-1968"}, {PG_LATIN1, "ISO-8859-1"}, {PG_LATIN1, "ISO8859-1"},