diff --git a/modules/libmar/src/mar.h b/modules/libmar/src/mar.h index aa717eef174..45f46e835a7 100644 --- a/modules/libmar/src/mar.h +++ b/modules/libmar/src/mar.h @@ -76,6 +76,10 @@ typedef int (* MarItemCallback)(MarFile *mar, const MarItem *item, void *data); */ MarFile *mar_open(const char *path); +#ifdef XP_WIN +MarFile *mar_wopen(const PRUnichar *path); +#endif + /** * Close a MAR file that was opened using mar_open. * @param mar The MarFile object to close. diff --git a/modules/libmar/src/mar_read.c b/modules/libmar/src/mar_read.c index 8ae3a771da4..b8468c2d13c 100644 --- a/modules/libmar/src/mar_read.c +++ b/modules/libmar/src/mar_read.c @@ -179,13 +179,13 @@ static int mar_read_index(MarFile *mar) { return (bufptr == bufend) ? 0 : -1; } -MarFile *mar_open(const char *path) { +/** + * Internal shared code for mar_open and mar_wopen. + * On failure, will fclose(fp). + */ +static MarFile *mar_fpopen(FILE *fp) +{ MarFile *mar; - FILE *fp; - - fp = fopen(path, "rb"); - if (!fp) - return NULL; mar = (MarFile *) malloc(sizeof(*mar)); if (!mar) { @@ -203,6 +203,28 @@ MarFile *mar_open(const char *path) { return mar; } +MarFile *mar_open(const char *path) { + FILE *fp; + + fp = fopen(path, "rb"); + if (!fp) + return NULL; + + return mar_fpopen(fp); +} + +#ifdef XP_WIN +MarFile *mar_wopen(const PRUnichar *path) { + FILE *fp; + + fp = _wfopen(path, L"rb"); + if (!fp) + return NULL; + + return mar_fpopen(fp); +} +#endif + void mar_close(MarFile *mar) { MarItem *item; int i; diff --git a/toolkit/mozapps/update/src/updater/archivereader.cpp b/toolkit/mozapps/update/src/updater/archivereader.cpp index 47f9390ff65..e17e0446720 100644 --- a/toolkit/mozapps/update/src/updater/archivereader.cpp +++ b/toolkit/mozapps/update/src/updater/archivereader.cpp @@ -49,12 +49,20 @@ #endif int +#ifdef XP_WIN +ArchiveReader::Open(const WCHAR *path) +#else ArchiveReader::Open(const char *path) +#endif { if (mArchive) Close(); +#ifdef XP_WIN + mArchive = mar_wopen(path); +#else mArchive = mar_open(path); +#endif if (!mArchive) return READ_ERROR; diff --git a/toolkit/mozapps/update/src/updater/archivereader.h b/toolkit/mozapps/update/src/updater/archivereader.h index 05ab38dce5f..2421faedee9 100644 --- a/toolkit/mozapps/update/src/updater/archivereader.h +++ b/toolkit/mozapps/update/src/updater/archivereader.h @@ -49,7 +49,12 @@ public: ArchiveReader() : mArchive(NULL) {} ~ArchiveReader() { Close(); } +#ifdef XP_WIN + int Open(const WCHAR *path); +#else int Open(const char *path); +#endif + void Close(); int ExtractFile(const char *item, const char *destination); diff --git a/toolkit/mozapps/update/src/updater/updater.cpp b/toolkit/mozapps/update/src/updater/updater.cpp index 530e2ba24dd..52027c9d0cc 100644 --- a/toolkit/mozapps/update/src/updater/updater.cpp +++ b/toolkit/mozapps/update/src/updater/updater.cpp @@ -1127,10 +1127,10 @@ WriteStatusFile(int status) { // This is how we communicate our completion status to the main application. - char filename[MAXPATHLEN]; - snprintf(filename, MAXPATHLEN, "%s/update.status", gSourcePath); + NS_tchar filename[MAXPATHLEN]; + NS_tsnprintf(filename, MAXPATHLEN, NS_T("%s/update.status"), gSourcePath); - AutoFD fd = ensure_open(filename, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY, 0644); + AutoFD fd = NS_topen(filename, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY, 0644); if (fd < 0) return; @@ -1151,8 +1151,8 @@ UpdateThreadFunc(void *param) { // open ZIP archive and process... - char dataFile[MAXPATHLEN]; - snprintf(dataFile, MAXPATHLEN, "%s/update.mar", gSourcePath); + NS_tchar dataFile[MAXPATHLEN]; + NS_tsnprintf(dataFile, MAXPATHLEN, NS_T("%s/update.mar"), gSourcePath); int rv = gArchiveReader.Open(dataFile); if (rv == OK) {