diff options
| author | 2018-07-19 09:03:30 -0400 | |
|---|---|---|
| committer | 2018-07-19 09:15:38 -0400 | |
| commit | e0b8a35937e5c93ce661e9a947bd2b5f68aa810f (patch) | |
| tree | 76438b697194444d6a2a16d3bd885758abd8bccd /src/common/misc.cpp | |
| parent | Merge pull request #700 from bunnei/update-dynarmic (diff) | |
| download | yuzu-e0b8a35937e5c93ce661e9a947bd2b5f68aa810f.tar.gz yuzu-e0b8a35937e5c93ce661e9a947bd2b5f68aa810f.tar.xz yuzu-e0b8a35937e5c93ce661e9a947bd2b5f68aa810f.zip | |
common/misc: Deduplicate code in GetLastErrorMsg()
Android and macOS have supported thread_local for quite a while, but
most importantly is that we don't even really need it. Instead of using
a thread-local buffer, we can just return a non-static buffer as a
std::string, avoiding the need for that quality entirely.
Diffstat (limited to 'src/common/misc.cpp')
| -rw-r--r-- | src/common/misc.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 7be2235b0..217a87098 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp | |||
| @@ -4,34 +4,28 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstddef> | 5 | #include <cstddef> |
| 6 | #ifdef _WIN32 | 6 | #ifdef _WIN32 |
| 7 | #include <windows.h> | 7 | #include <Windows.h> |
| 8 | #else | 8 | #else |
| 9 | #include <cerrno> | 9 | #include <cerrno> |
| 10 | #include <cstring> | 10 | #include <cstring> |
| 11 | #endif | 11 | #endif |
| 12 | 12 | ||
| 13 | // Neither Android nor OS X support TLS | 13 | #include "common/common_funcs.h" |
| 14 | #if defined(__APPLE__) || (ANDROID && __clang__) | ||
| 15 | #define __thread | ||
| 16 | #endif | ||
| 17 | 14 | ||
| 18 | // Generic function to get last error message. | 15 | // Generic function to get last error message. |
| 19 | // Call directly after the command or use the error num. | 16 | // Call directly after the command or use the error num. |
| 20 | // This function might change the error code. | 17 | // This function might change the error code. |
| 21 | const char* GetLastErrorMsg() { | 18 | std::string GetLastErrorMsg() { |
| 22 | static const size_t buff_size = 255; | 19 | static const size_t buff_size = 255; |
| 20 | char err_str[buff_size]; | ||
| 23 | 21 | ||
| 24 | #ifdef _WIN32 | 22 | #ifdef _WIN32 |
| 25 | static __declspec(thread) char err_str[buff_size] = {}; | ||
| 26 | |||
| 27 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), | 23 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), |
| 28 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); | 24 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); |
| 29 | #else | 25 | #else |
| 30 | static __thread char err_str[buff_size] = {}; | ||
| 31 | |||
| 32 | // Thread safe (XSI-compliant) | 26 | // Thread safe (XSI-compliant) |
| 33 | strerror_r(errno, err_str, buff_size); | 27 | strerror_r(errno, err_str, buff_size); |
| 34 | #endif | 28 | #endif |
| 35 | 29 | ||
| 36 | return err_str; | 30 | return std::string(err_str, buff_size); |
| 37 | } | 31 | } |