2014-01-25 08:51:03 -05:00
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "Errors.h"
|
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
AString GetOSErrorString( int a_ErrNo)
|
2014-01-25 08:51:03 -05:00
|
|
|
{
|
|
|
|
char buffer[ 1024 ];
|
|
|
|
AString Out;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, a_ErrNo, 0, buffer, ARRAYCOUNT(buffer), nullptr);
|
2014-01-25 08:51:03 -05:00
|
|
|
Printf(Out, "%d: %s", a_ErrNo, buffer);
|
|
|
|
if (!Out.empty() && (Out[Out.length() - 1] == '\n'))
|
|
|
|
{
|
|
|
|
Out.erase(Out.length() - 2);
|
|
|
|
}
|
|
|
|
return Out;
|
|
|
|
|
|
|
|
#else // _WIN32
|
|
|
|
|
|
|
|
// According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r():
|
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
#if !defined(__APPLE__) && ( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r()
|
2014-01-25 08:51:03 -05:00
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
|
2014-10-20 16:55:07 -04:00
|
|
|
if (res != nullptr)
|
2014-01-25 08:51:03 -05:00
|
|
|
{
|
|
|
|
Printf(Out, "%d: %s", a_ErrNo, res);
|
|
|
|
return Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // XSI version of strerror_r():
|
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
|
|
|
|
if (res == 0)
|
2014-01-25 08:51:03 -05:00
|
|
|
{
|
|
|
|
Printf(Out, "%d: %s", a_ErrNo, buffer);
|
|
|
|
return Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // strerror_r() version
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf(Out, "Error %d while getting error string for error #%d!", errno, a_ErrNo);
|
|
|
|
return Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // else _WIN32
|
|
|
|
}
|
2014-01-25 09:02:20 -05:00
|
|
|
|