Make "GetLastErrorMsg" thread safe.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7359 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
52cb7fd4ca
commit
2692ba2697
|
@ -20,19 +20,22 @@
|
||||||
// Generic function to get last error message.
|
// Generic function to get last error message.
|
||||||
// Call directly after the command or use the error num.
|
// Call directly after the command or use the error num.
|
||||||
// This function might change the error code.
|
// This function might change the error code.
|
||||||
const char *GetLastErrorMsg()
|
const char* GetLastErrorMsg()
|
||||||
{
|
{
|
||||||
// FIXME : not thread safe.
|
static const size_t buff_size = 255;
|
||||||
// Caused by sloppy use in logging in FileUtil.cpp, primarily. What to do, what to do ...
|
|
||||||
static char errStr[255] = {0};
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD dw = GetLastError();
|
static __declspec(thread) char err_str[buff_size] = {};
|
||||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dw,
|
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
|
||||||
(LPTSTR) errStr, 254, NULL );
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
err_str, buff_size, NULL);
|
||||||
#else
|
#else
|
||||||
|
static __thread char err_str[buff_size] = {};
|
||||||
|
|
||||||
// Thread safe (XSI-compliant)
|
// Thread safe (XSI-compliant)
|
||||||
strerror_r(errno, errStr, 255);
|
strerror_r(errno, err_str, buff_size);
|
||||||
#endif
|
#endif
|
||||||
return errStr;
|
|
||||||
|
return err_str;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue