mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Move SocketManager's DecodeError to Common
Fix thread safety issue
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#else
|
||||
@ -545,4 +546,24 @@ void RestoreNetworkErrorState(const NetworkErrorState& state)
|
||||
WSASetLastError(state.wsa_error);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* DecodeNetworkError(s32 error_code)
|
||||
{
|
||||
thread_local char buffer[1024];
|
||||
#define IS_BSD_STRERROR \
|
||||
defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(ANDROID) || \
|
||||
defined(__APPLE__)
|
||||
#ifdef _WIN32
|
||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
|
||||
FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
||||
nullptr, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer,
|
||||
sizeof(buffer), nullptr);
|
||||
return buffer;
|
||||
#elif (IS_BSD_STRERROR) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)
|
||||
strerror_r(error_code, buffer, sizeof(buffer));
|
||||
return buffer;
|
||||
#else
|
||||
return strerror_r(error_code, buffer, sizeof(buffer));
|
||||
#endif
|
||||
}
|
||||
} // namespace Common
|
||||
|
Reference in New Issue
Block a user