summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/common_funcs.h4
-rw-r--r--src/common/misc.cpp16
2 files changed, 8 insertions, 12 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 995938d0b..042c2c2aa 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -4,6 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <string>
8
7#if !defined(ARCHITECTURE_x86_64) && !defined(ARCHITECTURE_ARM) 9#if !defined(ARCHITECTURE_x86_64) && !defined(ARCHITECTURE_ARM)
8#include <cstdlib> // for exit 10#include <cstdlib> // for exit
9#endif 11#endif
@@ -90,7 +92,7 @@ __declspec(dllimport) void __stdcall DebugBreak(void);
90// Call directly after the command or use the error num. 92// Call directly after the command or use the error num.
91// This function might change the error code. 93// This function might change the error code.
92// Defined in Misc.cpp. 94// Defined in Misc.cpp.
93const char* GetLastErrorMsg(); 95std::string GetLastErrorMsg();
94 96
95namespace Common { 97namespace Common {
96 98
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}