summaryrefslogtreecommitdiff
path: root/src/common/misc.cpp
diff options
context:
space:
mode:
authorGravatar Morph2021-09-08 14:36:20 -0400
committerGravatar Morph2021-09-11 17:19:14 -0400
commit290afc00d36bbdcdc67d66a4586fd2f188734ad3 (patch)
treed4f9a8eae42dd93ff1e7393ffea03b30faeab125 /src/common/misc.cpp
parentMerge pull request #6846 from ameerj/nvdec-gpu-decode (diff)
downloadyuzu-290afc00d36bbdcdc67d66a4586fd2f188734ad3.tar.gz
yuzu-290afc00d36bbdcdc67d66a4586fd2f188734ad3.tar.xz
yuzu-290afc00d36bbdcdc67d66a4586fd2f188734ad3.zip
common: Move error handling to error.cpp/h
This allows us to avoid implicitly including <string> every time common_funcs.h is included.
Diffstat (limited to 'src/common/misc.cpp')
-rw-r--r--src/common/misc.cpp52
1 files changed, 0 insertions, 52 deletions
diff --git a/src/common/misc.cpp b/src/common/misc.cpp
deleted file mode 100644
index 495385b9e..000000000
--- a/src/common/misc.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstddef>
6#ifdef _WIN32
7#include <windows.h>
8#else
9#include <cerrno>
10#include <cstring>
11#endif
12
13#include "common/common_funcs.h"
14
15std::string NativeErrorToString(int e) {
16#ifdef _WIN32
17 LPSTR err_str;
18
19 DWORD res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER |
20 FORMAT_MESSAGE_IGNORE_INSERTS,
21 nullptr, e, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
22 reinterpret_cast<LPSTR>(&err_str), 1, nullptr);
23 if (!res) {
24 return "(FormatMessageA failed to format error)";
25 }
26 std::string ret(err_str);
27 LocalFree(err_str);
28 return ret;
29#else
30 char err_str[255];
31#if defined(__GLIBC__) && (_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600))
32 // Thread safe (GNU-specific)
33 const char* str = strerror_r(e, err_str, sizeof(err_str));
34 return std::string(str);
35#else
36 // Thread safe (XSI-compliant)
37 int second_err = strerror_r(e, err_str, sizeof(err_str));
38 if (second_err != 0) {
39 return "(strerror_r failed to format error)";
40 }
41 return std::string(err_str);
42#endif // GLIBC etc.
43#endif // _WIN32
44}
45
46std::string GetLastErrorMsg() {
47#ifdef _WIN32
48 return NativeErrorToString(GetLastError());
49#else
50 return NativeErrorToString(errno);
51#endif
52}