diff options
| author | 2020-10-30 00:35:40 -0700 | |
|---|---|---|
| committer | 2020-10-30 00:35:40 -0700 | |
| commit | 8aa9ae5ba5269b0c82f771a6fcf47b2534b5faf9 (patch) | |
| tree | 1eaa9ee780dab30783252f6ab68af1e8e62f3f07 /src/common/misc.cpp | |
| parent | Merge pull request #4867 from lioncash/vp9 (diff) | |
| parent | General: Catch more expressions with no effect on MSVC (diff) | |
| download | yuzu-8aa9ae5ba5269b0c82f771a6fcf47b2534b5faf9.tar.gz yuzu-8aa9ae5ba5269b0c82f771a6fcf47b2534b5faf9.tar.xz yuzu-8aa9ae5ba5269b0c82f771a6fcf47b2534b5faf9.zip | |
Merge pull request #4868 from lioncash/discard-error
General: Make ignoring a discarded return value an error
Diffstat (limited to 'src/common/misc.cpp')
| -rw-r--r-- | src/common/misc.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 68cb86cd1..1d5393597 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp | |||
| @@ -16,16 +16,23 @@ | |||
| 16 | // Call directly after the command or use the error num. | 16 | // Call directly after the command or use the error num. |
| 17 | // This function might change the error code. | 17 | // This function might change the error code. |
| 18 | std::string GetLastErrorMsg() { | 18 | std::string GetLastErrorMsg() { |
| 19 | static const std::size_t buff_size = 255; | 19 | static constexpr std::size_t buff_size = 255; |
| 20 | char err_str[buff_size]; | 20 | char err_str[buff_size]; |
| 21 | 21 | ||
| 22 | #ifdef _WIN32 | 22 | #ifdef _WIN32 |
| 23 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), | 23 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), |
| 24 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); | 24 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); |
| 25 | return std::string(err_str, buff_size); | ||
| 26 | #elif defined(__GLIBC__) && (_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600)) | ||
| 27 | // Thread safe (GNU-specific) | ||
| 28 | const char* str = strerror_r(errno, err_str, buff_size); | ||
| 29 | return std::string(str); | ||
| 25 | #else | 30 | #else |
| 26 | // Thread safe (XSI-compliant) | 31 | // Thread safe (XSI-compliant) |
| 27 | strerror_r(errno, err_str, buff_size); | 32 | const int success = strerror_r(errno, err_str, buff_size); |
| 33 | if (success != 0) { | ||
| 34 | return {}; | ||
| 35 | } | ||
| 36 | return std::string(err_str); | ||
| 28 | #endif | 37 | #endif |
| 29 | |||
| 30 | return std::string(err_str, buff_size); | ||
| 31 | } | 38 | } |