From 1bad6bc4a284da231798dccd8155947e314be5c4 Mon Sep 17 00:00:00 2001 From: yami-hack Date: Mon, 13 Jun 2016 21:21:13 +0800 Subject: [PATCH] Remove unnecessary code,using secure API Signed-off-by: yami-hack --- CMakeLists.txt | 4 ++++ src/common/file_util.cpp | 11 ----------- src/common/string_util.cpp | 6 +++--- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7b0af115..e04bd259f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,10 @@ if (NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1") endif() + + if (MINGW) + add_definitions(-DMINGW_HAS_SECURE_API) + endif() else() # Silence "deprecation" warnings add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /D_SCL_SECURE_NO_WARNINGS) diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index b059e8be8..17af7c385 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -9,7 +9,6 @@ #include "common/logging/log.h" #ifdef _WIN32 - #include #include #include // for SHGetFolderPath #include @@ -928,11 +927,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[]) { Close(); #ifdef _WIN32 -#if defined(__MINGW64__) && !defined(MINGW_HAS_SECURE_API) - 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 @@ -985,16 +980,10 @@ bool IOFile::Flush() bool IOFile::Resize(u64 size) { if (!IsOpen() || 0 != - #ifdef _WIN32 -#if defined(__MINGW64__) && !defined(MINGW_HAS_SECURE_API) - //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 37107f005..29bcb8381 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -52,7 +52,7 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar { int writtenCount; -#if defined(_MSC_VER) +#ifdef _MSC_VER // You would think *printf are simple, right? Iterate on each character, // if it's a format specifier handle it properly, etc. // @@ -296,7 +296,7 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st std::string UTF16ToUTF8(const std::u16string& input) { -#if _MSC_VER >= 1900 || defined(__MINGW64__) +#if _MSC_VER >= 1900 // 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 || defined(__MINGW64__) +#if _MSC_VER >= 1900 // Workaround for missing char16_t/char32_t instantiations in MSVC2015 std::wstring_convert, __int16> convert; auto tmp_buffer = convert.from_bytes(input);