summaryrefslogtreecommitdiff
path: root/src/common/misc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/misc.cpp')
-rw-r--r--src/common/misc.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/common/misc.cpp b/src/common/misc.cpp
new file mode 100644
index 000000000..935805478
--- /dev/null
+++ b/src/common/misc.cpp
@@ -0,0 +1,37 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "common.h"
6
7#ifdef _WIN32
8#include <windows.h>
9#endif
10
11// Neither Android nor OS X support TLS
12#if defined(__APPLE__) || (ANDROID && __clang__)
13#define __thread
14#endif
15
16// Generic function to get last error message.
17// Call directly after the command or use the error num.
18// This function might change the error code.
19const char* GetLastErrorMsg()
20{
21 static const size_t buff_size = 255;
22
23#ifdef _WIN32
24 static __declspec(thread) char err_str[buff_size] = {};
25
26 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
27 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
28 err_str, buff_size, NULL);
29#else
30 static __thread char err_str[buff_size] = {};
31
32 // Thread safe (XSI-compliant)
33 strerror_r(errno, err_str, buff_size);
34#endif
35
36 return err_str;
37}