diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 17af7c385..751d17d96 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -9,6 +9,7 @@ #include "common/logging/log.h" #ifdef _WIN32 + #include #include #include // for SHGetFolderPath #include @@ -927,7 +928,11 @@ bool IOFile::Open(const std::string& filename, const char openmode[]) { Close(); #ifdef _WIN32 +#if defined(__MINGW64__) + m_file = _wfsopen(Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str(),SH_DENYNO); +#else _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str()); +#endif #else m_file = fopen(filename.c_str(), openmode); #endif @@ -980,10 +985,16 @@ bool IOFile::Flush() bool IOFile::Resize(u64 size) { if (!IsOpen() || 0 != + #ifdef _WIN32 +#if defined(__MINGW64__) + //TDM-GCC64 does not supports _chsize_s ?in + _chsize(_fileno(m_file), size) +#else // ector: _chsize sucks, not 64-bit safe // F|RES: changed to _chsize_s. i think it is 64-bit safe _chsize_s(_fileno(m_file), size) +#endif #else // TODO: handle 64bit and growing ftruncate(fileno(m_file), size) diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index f0aa072db..4cd7cd44a 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -13,7 +13,7 @@ #include "common/logging/log.h" #include "common/string_util.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) || __MINGW64__ #include #include #include "common/common_funcs.h" @@ -52,7 +52,7 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar { int writtenCount; -#ifdef _MSC_VER +#if defined(_MSC_VER) || !defined(__MINGW64__) // You would think *printf are simple, right? Iterate on each character, // if it's a format specifier handle it properly, etc. // @@ -292,11 +292,11 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st return result; } -#ifdef _MSC_VER +#if defined(_MSC_VER) || !__MINGW32__ || __MINGW64__ std::string UTF16ToUTF8(const std::u16string& input) { -#if _MSC_VER >= 1900 +#if _MSC_VER >= 1900 && defined(__MINGW64__) // Workaround for missing char16_t/char32_t instantiations in MSVC2015 std::wstring_convert, __int16> convert; std::basic_string<__int16> tmp_buffer(input.cbegin(), input.cend()); @@ -309,7 +309,7 @@ std::string UTF16ToUTF8(const std::u16string& input) std::u16string UTF8ToUTF16(const std::string& input) { -#if _MSC_VER >= 1900 +#if _MSC_VER >= 1900 && defined(__MINGW64__) // Workaround for missing char16_t/char32_t instantiations in MSVC2015 std::wstring_convert, __int16> convert; auto tmp_buffer = convert.from_bytes(input); @@ -323,13 +323,11 @@ std::u16string UTF8ToUTF16(const std::string& input) static std::wstring CPToUTF16(u32 code_page, const std::string& input) { auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast(input.size()), nullptr, 0); - - std::wstring output; + std::wstring output(size,'\0'); output.resize(size); if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast(input.size()), &output[0], static_cast(output.size()))) output.clear(); - return output; } diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 28d403158..b62aba24e 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -14,7 +14,7 @@ #include #include -#ifdef _MSC_VER +#if defined(_MSC_VER) || (__MINGW64__) #include #include #include