From c971cf439cec3d412e297199db2416523c1a889d Mon Sep 17 00:00:00 2001 From: "ted.mielczarek@gmail.com" Date: Mon, 3 Nov 2014 17:05:39 +0000 Subject: Fix Windows client compilation on mingw. A=Jacek Caban , R=ted at http://breakpad.appspot.com/548002/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1399 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/common/windows/guid_string.h | 2 +- src/common/windows/http_upload.cc | 14 ++++++++------ src/common/windows/http_upload.h | 13 +++++++++---- src/common/windows/string_utils.cc | 8 ++++---- 4 files changed, 22 insertions(+), 15 deletions(-) (limited to 'src/common/windows') diff --git a/src/common/windows/guid_string.h b/src/common/windows/guid_string.h index 6b92675b..48a5c1d3 100644 --- a/src/common/windows/guid_string.h +++ b/src/common/windows/guid_string.h @@ -32,7 +32,7 @@ #ifndef COMMON_WINDOWS_GUID_STRING_H_ #define COMMON_WINDOWS_GUID_STRING_H_ -#include +#include #include diff --git a/src/common/windows/http_upload.cc b/src/common/windows/http_upload.cc index 838185b7..ba04d7d0 100644 --- a/src/common/windows/http_upload.cc +++ b/src/common/windows/http_upload.cc @@ -327,11 +327,13 @@ bool HTTPUpload::GetFileContents(const wstring &filename, // wchar_t* filename, so use _wfopen directly in that case. For VC8 and // later, _wfopen has been deprecated in favor of _wfopen_s, which does // not exist in earlier versions, so let the ifstream open the file itself. -#if _MSC_VER >= 1400 // MSVC 2005/8 + // GCC doesn't support wide file name and opening on FILE* requires ugly + // hacks, so fallback to multi byte file. +#ifdef _MSC_VER ifstream file; file.open(filename.c_str(), ios::binary); -#else // _MSC_VER >= 1400 - ifstream file(_wfopen(filename.c_str(), L"rb")); +#else // GCC + ifstream file(WideToMBCP(filename, CP_ACP).c_str(), ios::binary); #endif // _MSC_VER >= 1400 if (file.is_open()) { file.seekg(0, ios::end); @@ -375,13 +377,13 @@ wstring HTTPUpload::UTF8ToWide(const string &utf8) { } // static -string HTTPUpload::WideToUTF8(const wstring &wide) { +string HTTPUpload::WideToMBCP(const wstring &wide, unsigned int cp) { if (wide.length() == 0) { return string(); } // compute the length of the buffer we'll need - int charcount = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, + int charcount = WideCharToMultiByte(cp, 0, wide.c_str(), -1, NULL, 0, NULL, NULL); if (charcount == 0) { return string(); @@ -389,7 +391,7 @@ string HTTPUpload::WideToUTF8(const wstring &wide) { // convert char *buf = new char[charcount]; - WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, buf, charcount, + WideCharToMultiByte(cp, 0, wide.c_str(), -1, buf, charcount, NULL, NULL); string result(buf); diff --git a/src/common/windows/http_upload.h b/src/common/windows/http_upload.h index 0594cde3..e485b70e 100644 --- a/src/common/windows/http_upload.h +++ b/src/common/windows/http_upload.h @@ -38,8 +38,8 @@ // Disable exception handler warnings. #pragma warning(disable : 4530) -#include -#include +#include +#include #include #include @@ -80,7 +80,7 @@ class HTTPUpload { // this merely checks (via the return value) that we were successfully // able to retrieve exactly as many bytes of content in the response as // were specified in the Content-Length header. - static bool HTTPUpload::ReadResponse(HINTERNET request, wstring* response); + static bool ReadResponse(HINTERNET request, wstring* response); // Generates a new multipart boundary for a POST request static wstring GenerateMultipartBoundary(); @@ -104,7 +104,12 @@ class HTTPUpload { static wstring UTF8ToWide(const string &utf8); // Converts a UTF16 string to UTF8. - static string WideToUTF8(const wstring &wide); + static string WideToUTF8(const wstring &wide) { + return WideToMBCP(wide, CP_UTF8); + } + + // Converts a UTF16 string to specified code page. + static string WideToMBCP(const wstring &wide, unsigned int cp); // Checks that the given list of parameters has only printable // ASCII characters in the parameter name, and does not contain diff --git a/src/common/windows/string_utils.cc b/src/common/windows/string_utils.cc index e6ffa082..27280003 100644 --- a/src/common/windows/string_utils.cc +++ b/src/common/windows/string_utils.cc @@ -58,7 +58,7 @@ bool WindowsStringUtils::safe_mbstowcs(const string &mbs, wstring *wcs) { } assert(wcs_length > 0); #else // _MSC_VER >= 1400 - if ((wcs_length = mbstowcs(NULL, mbs.c_str(), mbs.length())) < 0) { + if ((wcs_length = mbstowcs(NULL, mbs.c_str(), mbs.length())) == (size_t)-1) { return false; } @@ -75,7 +75,7 @@ bool WindowsStringUtils::safe_mbstowcs(const string &mbs, wstring *wcs) { return false; } #else // _MSC_VER >= 1400 - if (mbstowcs(&wcs_v[0], mbs.c_str(), mbs.length()) < 0) { + if (mbstowcs(&wcs_v[0], mbs.c_str(), mbs.length()) == (size_t)-1) { return false; } @@ -101,7 +101,7 @@ bool WindowsStringUtils::safe_wcstombs(const wstring &wcs, string *mbs) { } assert(mbs_length > 0); #else // _MSC_VER >= 1400 - if ((mbs_length = wcstombs(NULL, wcs.c_str(), wcs.length())) < 0) { + if ((mbs_length = wcstombs(NULL, wcs.c_str(), wcs.length())) == (size_t)-1) { return false; } @@ -118,7 +118,7 @@ bool WindowsStringUtils::safe_wcstombs(const wstring &wcs, string *mbs) { return false; } #else // _MSC_VER >= 1400 - if (wcstombs(&mbs_v[0], wcs.c_str(), wcs.length()) < 0) { + if (wcstombs(&mbs_v[0], wcs.c_str(), wcs.length()) == (size_t)-1) { return false; } -- cgit v1.2.1