Bug 488157. Use UTF8 instead of native codepages during startup. r=bsmedberg

--HG--
extra : rebase_source : 22bea59e453f953f3efd43d6d945d9d9fee70ce5
This commit is contained in:
Hiroyuki Ikezoe 2009-05-13 22:16:45 +12:00
Родитель add6e0249f
Коммит 5059b28ee6
4 изменённых файлов: 63 добавлений и 14 удалений

Просмотреть файл

@ -45,11 +45,30 @@
#include <stdlib.h>
#include <stdio.h>
#ifdef XP_WIN
#include <windows.h>
#endif
#if defined(XP_WIN) || defined(XP_OS2)
#define BINARY_MODE "b"
#if defined(XP_WIN)
#define READ_BINARYMODE L"rb"
#elif defined(XP_OS2)
#define READ_BINARYMODE "rb"
#else
#define BINARY_MODE
#define READ_BINARYMODE "r"
#endif
#ifdef XP_WIN
inline FILE *TS_tfopen (const char *path, const wchar_t *mode)
{
wchar_t wPath[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, MAX_PATH);
return _wfopen(wPath, mode);
}
#else
inline FILE *TS_tfopen (const char *path, const char *mode)
{
return fopen(path, mode);
}
#endif
// Stack based FILE wrapper to ensure that fclose is called, copied from
@ -82,14 +101,14 @@ nsINIParser::Init(nsILocalFile* aFile)
rv = aFile->GetPath(path);
NS_ENSURE_SUCCESS(rv, rv);
fd = _wfopen(path.get(), L"rb");
fd = _wfopen(path.get(), READ_BINARYMODE);
#else
nsCAutoString path;
rv = aFile->GetNativePath(path);
NS_ENSURE_SUCCESS(rv, rv);
fd = fopen(path.get(), "r" BINARY_MODE);
fd = fopen(path.get(), READ_BINARYMODE);
#endif
if (!fd)
return NS_ERROR_FAILURE;
@ -100,7 +119,8 @@ nsresult
nsINIParser::Init(const char *aPath)
{
/* open the file */
AutoFILE fd = fopen(aPath, "r" BINARY_MODE);
AutoFILE fd = TS_tfopen(aPath, READ_BINARYMODE);
if (!fd)
return NS_ERROR_FAILURE;

Просмотреть файл

@ -77,7 +77,7 @@ static void
ReadDependentCB(const char *aDependentLib)
{
wchar_t wideDependentLib[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, aDependentLib, -1, wideDependentLib, MAX_PATH);
MultiByteToWideChar(CP_UTF8, 0, aDependentLib, -1, wideDependentLib, MAX_PATH);
HINSTANCE h =
LoadLibraryExW(wideDependentLib, NULL, MOZ_LOADLIBRARY_FLAGS);
@ -141,7 +141,7 @@ GetFrozenFunctionsFunc
XPCOMGlueLoad(const char *aXpcomFile)
{
wchar_t xpcomFile[MAXPATHLEN];
MultiByteToWideChar(CP_ACP, 0, aXpcomFile,-1,
MultiByteToWideChar(CP_UTF8, 0, aXpcomFile,-1,
xpcomFile, MAXPATHLEN);
@ -163,7 +163,7 @@ XPCOMGlueLoad(const char *aXpcomFile)
if (lastSlash) {
*lastSlash = '\0';
char xpcomDir_narrow[MAXPATHLEN];
WideCharToMultiByte(CP_ACP, 0, xpcomDir,-1,
WideCharToMultiByte(CP_UTF8, 0, xpcomDir,-1,
xpcomDir_narrow, MAX_PATH, NULL, NULL);
XPCOMGlueLoadDependentLibs(xpcomDir_narrow, ReadDependentCB);

Просмотреть файл

@ -82,10 +82,26 @@ nsresult XPCOMGlueStartup(const char* xpcomFile)
return NS_OK;
}
#if defined(XP_WIN) || defined(XP_OS2)
#define READ_TEXTMODE "t"
#if defined(XP_WIN)
#define READ_TEXTMODE L"rt"
#elif defined(XP_OS2)
#define READ_TEXTMODE "rt"
#else
#define READ_TEXTMODE
#define READ_TEXTMODE "r"
#endif
#ifdef XP_WIN
inline FILE *TS_tfopen (const char *path, const wchar_t *mode)
{
wchar_t wPath[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, MAX_PATH);
return _wfopen(wPath, mode);
}
#else
inline FILE *TS_tfopen (const char *path, const char *mode)
{
return fopen(path, mode);
}
#endif
void
@ -95,7 +111,7 @@ XPCOMGlueLoadDependentLibs(const char *xpcomDir, DependentLibsCallback cb)
sprintf(buffer, "%s" XPCOM_FILE_PATH_SEPARATOR XPCOM_DEPENDENT_LIBS_LIST,
xpcomDir);
FILE *flist = fopen(buffer, "r" READ_TEXTMODE);
FILE *flist = TS_tfopen(buffer, READ_TEXTMODE);
if (!flist)
return;

Просмотреть файл

@ -454,8 +454,15 @@ main(int argc, char **argv)
{ // Scope COMPtr and AutoAppData
nsCOMPtr<nsILocalFile> iniFile;
#ifdef XP_WIN
// On Windows and Windows CE, iniPath is UTF-8 encoded,
// so we need to convert it.
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(iniPath), PR_FALSE,
getter_AddRefs(iniFile));
#else
rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), PR_FALSE,
getter_AddRefs(iniFile));
#endif
if (NS_FAILED(rv)) {
Output(PR_TRUE, "Couldn't find application.ini file.\n");
return 1;
@ -475,8 +482,14 @@ main(int argc, char **argv)
if (lastSlash) {
*lastSlash = '\0';
}
#ifdef XP_WIN
// same as iniPath.
NS_NewLocalFile(NS_ConvertUTF8toUTF16(greDir), PR_FALSE,
&appData->xreDirectory);
#else
NS_NewNativeLocalFile(nsDependentCString(greDir), PR_FALSE,
&appData->xreDirectory);
#endif
}
retval = XRE_main(argc, argv, appData);