Skip to content

Instantly share code, notes, and snippets.

@pcan
Created January 6, 2017 10:01
Show Gist options
  • Save pcan/7303c7cd5ee75cf93e6ea0e7b8997fb8 to your computer and use it in GitHub Desktop.
Save pcan/7303c7cd5ee75cf93e6ea0e7b8997fb8 to your computer and use it in GitHub Desktop.
gai_strerror Shim for Luasocket static lib (compiled with MinGW)
/*
Specify the following options for the linker:
-Wl,--enable-stdcall-fixup
*/
#include "ws2tcpip.h"
char *
gai_strerrorA(
_In_ int ecode)
{
DWORD dwMsgLen;
static char buff[GAI_STRERROR_BUFFER_SIZE + 1];
dwMsgLen = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_IGNORE_INSERTS
|FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL,
ecode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)buff,
GAI_STRERROR_BUFFER_SIZE,
NULL);
return buff;
}
WCHAR *
gai_strerrorW(
_In_ int ecode
)
{
DWORD dwMsgLen;
static WCHAR buff[GAI_STRERROR_BUFFER_SIZE + 1];
dwMsgLen = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_IGNORE_INSERTS
|FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL,
ecode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)buff,
GAI_STRERROR_BUFFER_SIZE,
NULL);
return buff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment