From 5215468ff61cc7e1f1773db4068aa84303e2f298 Mon Sep 17 00:00:00 2001 From: SachinVin <26602104+SachinVin@users.noreply.github.com> Date: Wed, 15 Feb 2023 02:49:45 +0530 Subject: [PATCH] core\file_sys\archive_sdmc.cpp: Log error message if file failed to open. (#6284) --- src/common/misc.cpp | 11 +++++++---- src/core/file_sys/archive_sdmc.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 68cb86cd1..59258749b 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -16,16 +16,19 @@ // Call directly after the command or use the error num. // This function might change the error code. std::string GetLastErrorMsg() { - static const std::size_t buff_size = 255; + constexpr std::size_t buff_size = 255; char err_str[buff_size]; + std::size_t msg_len; #ifdef _WIN32 - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); + msg_len = + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); #else // Thread safe (XSI-compliant) strerror_r(errno, err_str, buff_size); + msg_len = strnlen(err_str, buff_size); #endif - return std::string(err_str, buff_size); + return std::string(err_str, msg_len); } diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index a68e6bf34..9164d48c6 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp @@ -106,7 +106,7 @@ ResultVal> SDMCArchive::OpenFileBase(const Path& pa FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb"); if (!file.IsOpen()) { - LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path); + LOG_CRITICAL(Service_FS, "Error opening {}: {}", full_path, GetLastErrorMsg()); return ERROR_NOT_FOUND; }