Creating a quick get_WSAErrorStr function to act as a wrapper for FormatMessageA so we can string-ify Winsock errors properly

Untested!
This commit is contained in:
Monster Iestyn 2018-10-13 20:44:01 +01:00
parent 0e6c5cf342
commit ab38e6cebb
1 changed files with 22 additions and 0 deletions

View File

@ -262,6 +262,28 @@ static void wattcp_outch(char s)
}
#endif
#ifdef USE_WINSOCK
// stupid microsoft makes things complicated
static inline char *get_WSAErrorStr(int e)
{
char *buf = NULL;
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
(DWORD)e,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buf,
0, NULL);
return buf;
}
#undef strerror
#define strerror get_WSAErrorStr
#endif
#ifdef USE_WINSOCK2
#define inet_ntop inet_ntopA
#define HAVE_NTOP