summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Misc.cpp
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2015-06-10 00:00:12 +0200
committerJules Blok <jules.blok@gmail.com>2015-06-10 00:00:12 +0200
commit7dfced21a2e5aac7195e0e1ad76468e30306766b (patch)
treebd671b639d3d911460b767caabad8fc8a759a6bf /Source/Core/Common/Misc.cpp
parentc25be031fc1031d795157d8344b87b7841145197 (diff)
parent7b0a65e295c784f9d573f2ef52d4e2a7b9bb2889 (diff)
Merge branch 'master' into stable
Diffstat (limited to 'Source/Core/Common/Misc.cpp')
-rw-r--r--Source/Core/Common/Misc.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/Source/Core/Common/Misc.cpp b/Source/Core/Common/Misc.cpp
new file mode 100644
index 0000000000..849fa78c75
--- /dev/null
+++ b/Source/Core/Common/Misc.cpp
@@ -0,0 +1,30 @@
+// Copyright 2009 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include <cstddef>
+#include <cstring>
+#include <errno.h>
+
+#include "Common/CommonFuncs.h"
+
+// Generic function to get last error message.
+// Call directly after the command or use the error num.
+// This function might change the error code.
+std::string GetLastErrorMsg()
+{
+ const size_t buff_size = 256;
+ char err_str[buff_size];
+
+#ifdef _WIN32
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ err_str, buff_size, nullptr);
+#else
+ // Thread safe (XSI-compliant)
+ if (strerror_r(errno, err_str, buff_size))
+ return "";
+#endif
+
+ return std::string(err_str);
+}