| 15 | namespace Common { |
| 16 | |
| 17 | std::string NativeErrorToString(int e) { |
| 18 | #ifdef _WIN32 |
| 19 | LPSTR err_str; |
| 20 | |
| 21 | DWORD res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 22 | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 23 | nullptr, e, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 24 | reinterpret_cast<LPSTR>(&err_str), 1, nullptr); |
| 25 | if (!res) { |
| 26 | return "(FormatMessageA failed to format error)"; |
| 27 | } |
| 28 | std::string ret(err_str); |
| 29 | LocalFree(err_str); |
| 30 | return ret; |
| 31 | #else |
| 32 | char err_str[255]; |
| 33 | #if defined(ANDROID) || \ |
| 34 | (defined(__GLIBC__) && (_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600))) |
| 35 | // Thread safe (GNU-specific) |
| 36 | const char* str = strerror_r(e, err_str, sizeof(err_str)); |
| 37 | return std::string(str); |
| 38 | #else |
| 39 | // Thread safe (XSI-compliant) |
| 40 | int second_err = strerror_r(e, err_str, sizeof(err_str)); |
| 41 | if (second_err != 0) { |
| 42 | return "(strerror_r failed to format error)"; |
| 43 | } |
| 44 | return std::string(err_str); |
| 45 | #endif // GLIBC etc. |
| 46 | #endif // _WIN32 |
| 47 | } |
| 48 | |
| 49 | std::string GetLastErrorMsg() { |
| 50 | #ifdef _WIN32 |
no outgoing calls
no test coverage detected