2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2009-03-07 01:35:01 -07:00
|
|
|
|
2014-02-19 20:11:52 -07:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
|
|
|
#include <errno.h>
|
2009-03-07 01:35:01 -07:00
|
|
|
|
2013-04-18 21:52:53 -06:00
|
|
|
// Neither Android nor OS X support TLS
|
|
|
|
#if defined(__APPLE__) || (ANDROID && __clang__)
|
2011-03-16 16:58:24 -06:00
|
|
|
#define __thread
|
|
|
|
#endif
|
|
|
|
|
2009-03-07 01:35:01 -07: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.
|
2011-03-16 15:08:20 -06:00
|
|
|
const char* GetLastErrorMsg()
|
2009-03-07 01:35:01 -07:00
|
|
|
{
|
2011-03-16 15:08:20 -06:00
|
|
|
static const size_t buff_size = 255;
|
|
|
|
|
2009-03-07 01:35:01 -07:00
|
|
|
#ifdef _WIN32
|
2011-03-16 15:08:20 -06:00
|
|
|
static __declspec(thread) char err_str[buff_size] = {};
|
|
|
|
|
2014-03-09 14:14:26 -06:00
|
|
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
|
2011-03-16 15:08:20 -06:00
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
2014-03-09 14:14:26 -06:00
|
|
|
err_str, buff_size, nullptr);
|
2009-03-07 01:35:01 -07:00
|
|
|
#else
|
2011-03-16 15:08:20 -06:00
|
|
|
static __thread char err_str[buff_size] = {};
|
|
|
|
|
2009-03-07 01:35:01 -07:00
|
|
|
// Thread safe (XSI-compliant)
|
2011-03-16 15:08:20 -06:00
|
|
|
strerror_r(errno, err_str, buff_size);
|
2009-03-07 01:35:01 -07:00
|
|
|
#endif
|
2011-03-16 15:08:20 -06:00
|
|
|
|
|
|
|
return err_str;
|
2009-03-07 01:35:01 -07:00
|
|
|
}
|