2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2014-02-20 03:11:52 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
|
|
|
#include <errno.h>
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2014-09-19 04:17:41 +00:00
|
|
|
#include "Common/CommonFuncs.h"
|
|
|
|
|
2009-03-07 08:35:01 +00:00
|
|
|
// Generic function to get last error message.
|
|
|
|
// Call directly after the command or use the error num.
|
|
|
|
// This function might change the error code.
|
2015-04-07 20:15:21 +00:00
|
|
|
std::string GetLastErrorMsg()
|
2009-03-07 08:35:01 +00:00
|
|
|
{
|
2015-04-07 20:15:21 +00:00
|
|
|
const size_t buff_size = 256;
|
|
|
|
char err_str[buff_size];
|
2011-03-16 21:08:20 +00:00
|
|
|
|
2009-03-07 08:35:01 +00:00
|
|
|
#ifdef _WIN32
|
2014-03-09 20:14:26 +00:00
|
|
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
|
2011-03-16 21:08:20 +00:00
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
2014-03-09 20:14:26 +00:00
|
|
|
err_str, buff_size, nullptr);
|
2009-03-07 08:35:01 +00:00
|
|
|
#else
|
|
|
|
// Thread safe (XSI-compliant)
|
2015-02-24 00:38:14 +00:00
|
|
|
if (strerror_r(errno, err_str, buff_size))
|
2015-04-07 20:15:21 +00:00
|
|
|
return "";
|
2009-03-07 08:35:01 +00:00
|
|
|
#endif
|
2011-03-16 21:08:20 +00:00
|
|
|
|
2015-04-07 20:15:21 +00:00
|
|
|
return std::string(err_str);
|
2009-03-07 08:35:01 +00:00
|
|
|
}
|