summaryrefslogtreecommitdiff
path: root/src/common/misc.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-07-19 10:00:48 -0700
committerGravatar GitHub2018-07-19 10:00:48 -0700
commitbbc31ba6afdd56194d36fc4c99e0e07f7499fe8a (patch)
treebc1017dd2ba9d2b7e540aeb13a4af1368b2bde86 /src/common/misc.cpp
parentMerge pull request #708 from lioncash/xbyak (diff)
parentcommon/misc: Deduplicate code in GetLastErrorMsg() (diff)
downloadyuzu-bbc31ba6afdd56194d36fc4c99e0e07f7499fe8a.tar.gz
yuzu-bbc31ba6afdd56194d36fc4c99e0e07f7499fe8a.tar.xz
yuzu-bbc31ba6afdd56194d36fc4c99e0e07f7499fe8a.zip
Merge pull request #709 from lioncash/thread-local
common/misc: Deduplicate code in GetLastErrorMsg()
Diffstat (limited to 'src/common/misc.cpp')
-rw-r--r--src/common/misc.cpp16
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.
21const char* GetLastErrorMsg() { 18std::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}