diff options
author | bunnei <bunneidev@gmail.com> | 2020-04-07 23:48:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-07 23:48:16 -0400 |
commit | b128beb3a93736cb14643372348c455e116ba247 (patch) | |
tree | 12b873bd6451326f3d0780570b099e5a45961a4b /src/common/file_util.cpp | |
parent | 26ed65495d37f74afd12d2c7ed9b541189718bbd (diff) | |
parent | bd0c56c6e7ad506d7123c7e3aca85bd037275a5c (diff) |
Merge pull request #3572 from FearlessTobi/port-5127
Port citra-emu/citra#5127: "common: Port some changes from dolphin"
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r-- | src/common/file_util.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 41167f57a..35eee0096 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include <array> +#include <limits> #include <memory> #include <sstream> #include <unordered_map> @@ -530,11 +531,11 @@ void CopyDir(const std::string& source_path, const std::string& dest_path) { std::optional<std::string> GetCurrentDir() { // Get the current working directory (getcwd uses malloc) #ifdef _WIN32 - wchar_t* dir; - if (!(dir = _wgetcwd(nullptr, 0))) { + wchar_t* dir = _wgetcwd(nullptr, 0); + if (!dir) { #else - char* dir; - if (!(dir = getcwd(nullptr, 0))) { + char* dir = getcwd(nullptr, 0); + if (!dir) { #endif LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg()); return {}; @@ -918,19 +919,22 @@ void IOFile::Swap(IOFile& other) noexcept { bool IOFile::Open(const std::string& filename, const char openmode[], int flags) { Close(); + bool m_good; #ifdef _WIN32 if (flags != 0) { m_file = _wfsopen(Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str(), flags); + m_good = m_file != nullptr; } else { - _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), - Common::UTF8ToUTF16W(openmode).c_str()); + m_good = _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), + Common::UTF8ToUTF16W(openmode).c_str()) == 0; } #else - m_file = fopen(filename.c_str(), openmode); + m_file = std::fopen(filename.c_str(), openmode); + m_good = m_file != nullptr; #endif - return IsOpen(); + return m_good; } bool IOFile::Close() { @@ -956,7 +960,7 @@ u64 IOFile::Tell() const { if (IsOpen()) return ftello(m_file); - return -1; + return std::numeric_limits<u64>::max(); } bool IOFile::Flush() { |