Common: Remove TLS usage in GetLastErrorMsg
Just return std::string as this code isn't performance critical.
This commit is contained in:
parent
4796dc80bf
commit
ef6bdf674f
|
@ -16,6 +16,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ extern "C"
|
||||||
// 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.
|
||||||
// Defined in Misc.cpp.
|
// Defined in Misc.cpp.
|
||||||
const char* GetLastErrorMsg();
|
std::string GetLastErrorMsg();
|
||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
|
|
|
@ -97,7 +97,7 @@ bool IsDirectory(const std::string &filename)
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
{
|
{
|
||||||
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
|
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
|
||||||
filename.c_str(), GetLastErrorMsg());
|
filename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,14 +129,14 @@ bool Delete(const std::string &filename)
|
||||||
if (!DeleteFile(UTF8ToTStr(filename).c_str()))
|
if (!DeleteFile(UTF8ToTStr(filename).c_str()))
|
||||||
{
|
{
|
||||||
WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s",
|
WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s",
|
||||||
filename.c_str(), GetLastErrorMsg());
|
filename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (unlink(filename.c_str()) == -1)
|
if (unlink(filename.c_str()) == -1)
|
||||||
{
|
{
|
||||||
WARN_LOG(COMMON, "Delete: unlink failed on %s: %s",
|
WARN_LOG(COMMON, "Delete: unlink failed on %s: %s",
|
||||||
filename.c_str(), GetLastErrorMsg());
|
filename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -234,7 +234,7 @@ bool DeleteDir(const std::string &filename)
|
||||||
if (rmdir(filename.c_str()) == 0)
|
if (rmdir(filename.c_str()) == 0)
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
ERROR_LOG(COMMON, "DeleteDir: %s: %s", filename.c_str(), GetLastErrorMsg());
|
ERROR_LOG(COMMON, "DeleteDir: %s: %s", filename.c_str(), GetLastErrorMsg().c_str());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ bool Rename(const std::string &srcFilename, const std::string &destFilename)
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s",
|
ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
|
ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
||||||
if (!input.is_open())
|
if (!input.is_open())
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
|
ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
||||||
if (!output.IsOpen())
|
if (!output.IsOpen())
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
|
ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON,
|
ERROR_LOG(COMMON,
|
||||||
"Copy: failed reading from source, %s --> %s: %s",
|
"Copy: failed reading from source, %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +358,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON,
|
ERROR_LOG(COMMON,
|
||||||
"Copy: failed writing to output, %s --> %s: %s",
|
"Copy: failed writing to output, %s --> %s: %s",
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ u64 GetSize(const std::string &filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
ERROR_LOG(COMMON, "GetSize: Stat failed %s: %s",
|
ERROR_LOG(COMMON, "GetSize: Stat failed %s: %s",
|
||||||
filename.c_str(), GetLastErrorMsg());
|
filename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ u64 GetSize(const int fd)
|
||||||
if (fstat64(fd, &buf) != 0)
|
if (fstat64(fd, &buf) != 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "GetSize: stat failed %i: %s",
|
ERROR_LOG(COMMON, "GetSize: stat failed %i: %s",
|
||||||
fd, GetLastErrorMsg());
|
fd, GetLastErrorMsg().c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return buf.st_size;
|
return buf.st_size;
|
||||||
|
@ -420,7 +420,7 @@ u64 GetSize(FILE *f)
|
||||||
if (fseeko(f, 0, SEEK_END) != 0)
|
if (fseeko(f, 0, SEEK_END) != 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "GetSize: seek failed %p: %s",
|
ERROR_LOG(COMMON, "GetSize: seek failed %p: %s",
|
||||||
f, GetLastErrorMsg());
|
f, GetLastErrorMsg().c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ u64 GetSize(FILE *f)
|
||||||
if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0))
|
if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0))
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "GetSize: seek failed %p: %s",
|
ERROR_LOG(COMMON, "GetSize: seek failed %p: %s",
|
||||||
f, GetLastErrorMsg());
|
f, GetLastErrorMsg().c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ bool CreateEmptyFile(const std::string &filename)
|
||||||
if (!File::IOFile(filename, "wb"))
|
if (!File::IOFile(filename, "wb"))
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
|
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
|
||||||
filename.c_str(), GetLastErrorMsg());
|
filename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,7 +656,7 @@ std::string GetCurrentDir()
|
||||||
if (!(dir = __getcwd(nullptr, 0)))
|
if (!(dir = __getcwd(nullptr, 0)))
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "GetCurrentDirectory failed: %s",
|
ERROR_LOG(COMMON, "GetCurrentDirectory failed: %s",
|
||||||
GetLastErrorMsg());
|
GetLastErrorMsg().c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
std::string strDir = dir;
|
std::string strDir = dir;
|
||||||
|
|
|
@ -145,7 +145,7 @@ void FreeMemoryPages(void* ptr, size_t size)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (error_occurred)
|
if (error_occurred)
|
||||||
PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg());
|
PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ void ReadProtectMemory(void* ptr, size_t size)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (error_occurred)
|
if (error_occurred)
|
||||||
PanicAlert("ReadProtectMemory failed!\n%s", GetLastErrorMsg());
|
PanicAlert("ReadProtectMemory failed!\n%s", GetLastErrorMsg().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
|
void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
|
||||||
|
@ -196,7 +196,7 @@ void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (error_occurred)
|
if (error_occurred)
|
||||||
PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg());
|
PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
|
void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
|
||||||
|
@ -215,7 +215,7 @@ void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (error_occurred)
|
if (error_occurred)
|
||||||
PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
|
PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MemUsage()
|
std::string MemUsage()
|
||||||
|
|
|
@ -8,31 +8,23 @@
|
||||||
|
|
||||||
#include "Common/CommonFuncs.h"
|
#include "Common/CommonFuncs.h"
|
||||||
|
|
||||||
// Neither Android nor OS X support TLS
|
|
||||||
#if defined(__APPLE__) || (ANDROID && __clang__)
|
|
||||||
#define __thread
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 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()
|
std::string GetLastErrorMsg()
|
||||||
{
|
{
|
||||||
static const size_t buff_size = 255;
|
const size_t buff_size = 256;
|
||||||
|
char err_str[buff_size];
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static __declspec(thread) char err_str[buff_size] = {};
|
|
||||||
|
|
||||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
err_str, buff_size, nullptr);
|
err_str, buff_size, nullptr);
|
||||||
#else
|
#else
|
||||||
static __thread char err_str[buff_size] = {};
|
|
||||||
|
|
||||||
// Thread safe (XSI-compliant)
|
// Thread safe (XSI-compliant)
|
||||||
if (strerror_r(errno, err_str, buff_size))
|
if (strerror_r(errno, err_str, buff_size))
|
||||||
return nullptr;
|
return "";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return err_str;
|
return std::string(err_str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,6 +276,6 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const std::string& filename)
|
||||||
FailWrite:
|
FailWrite:
|
||||||
ERROR_LOG(COMMON, "Could not write to '%s', aborting...\n", filename.c_str());
|
ERROR_LOG(COMMON, "Could not write to '%s', aborting...\n", filename.c_str());
|
||||||
if (unlink(filename.c_str()) < 0)
|
if (unlink(filename.c_str()) < 0)
|
||||||
ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename.c_str(), GetLastErrorMsg());
|
ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename.c_str(), GetLastErrorMsg().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue