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:
Jordan Woyak 2011-03-16 21:08:20 +00:00
parent 52cb7fd4ca
commit 2692ba2697

View File

@ -22,17 +22,20 @@
// This function might change the error code.
const char* GetLastErrorMsg()
{
// FIXME : not thread safe.
// Caused by sloppy use in logging in FileUtil.cpp, primarily. What to do, what to do ...
static char errStr[255] = {0};
static const size_t buff_size = 255;
#ifdef _WIN32
DWORD dw = GetLastError();
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dw,
static __declspec(thread) char err_str[buff_size] = {};
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) errStr, 254, NULL );
err_str, buff_size, NULL);
#else
static __thread char err_str[buff_size] = {};
// Thread safe (XSI-compliant)
strerror_r(errno, errStr, 255);
strerror_r(errno, err_str, buff_size);
#endif
return errStr;
return err_str;
}