Skip to content

Commit

Permalink
fix(build): Use gai_strerrorA not gai_strerror on Windows
Browse files Browse the repository at this point in the history
* Explicitly call gai_strerrorA (for Windows builds), so that the code work correctly in 32bit or 64bit builds.

* Implement GAI_STRERROR macro to deal with Windows vs. Non-Windows compiles for 64-bit.

* make usocket.c consistent with other modules that call macro GAI_STRERROR

* Use different name not just different case for macro wrapping function

Co-authored-by: Caleb Maclennan <caleb@alerque.com>
  • Loading branch information
rpatters1 and alerque authored Jul 27, 2022
1 parent d1ad816 commit 5a7e3f0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/inet.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int inet_meth_getpeername(lua_State *L, p_socket ps, int family)
port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
if (err) {
lua_pushnil(L);
lua_pushstring(L, gai_strerror(err));
lua_pushstring(L, LUA_GAI_STRERROR(err));
return 2;
}
lua_pushstring(L, name);
Expand Down Expand Up @@ -286,7 +286,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
name, INET6_ADDRSTRLEN, port, 6, NI_NUMERICHOST | NI_NUMERICSERV);
if (err) {
lua_pushnil(L);
lua_pushstring(L, gai_strerror(err));
lua_pushstring(L, LUA_GAI_STRERROR(err));
return 2;
}
lua_pushstring(L, name);
Expand Down
2 changes: 2 additions & 0 deletions src/socket.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
\*=========================================================================*/
#ifdef _WIN32
#include "wsocket.h"
#define LUA_GAI_STRERROR gai_strerrorA
#else
#include "usocket.h"
#define LUA_GAI_STRERROR gai_strerror
#endif

/*=========================================================================*\
Expand Down
4 changes: 2 additions & 2 deletions src/udp.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static int meth_sendto(lua_State *L) {
err = getaddrinfo(ip, port, &aihint, &ai);
if (err) {
lua_pushnil(L);
lua_pushstring(L, gai_strerror(err));
lua_pushstring(L, LUA_GAI_STRERROR(err));
return 2;
}

Expand Down Expand Up @@ -290,7 +290,7 @@ static int meth_receivefrom(lua_State *L) {
INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV);
if (err) {
lua_pushnil(L);
lua_pushstring(L, gai_strerror(err));
lua_pushstring(L, LUA_GAI_STRERROR(err));
if (wanted > sizeof(buf)) free(dgram);
return 2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/usocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,6 @@ const char *socket_gaistrerror(int err) {
case EAI_SERVICE: return PIE_SERVICE;
case EAI_SOCKTYPE: return PIE_SOCKTYPE;
case EAI_SYSTEM: return strerror(errno);
default: return gai_strerror(err);
default: return LUA_GAI_STRERROR(err);
}
}
2 changes: 1 addition & 1 deletion src/wsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,6 @@ const char *socket_gaistrerror(int err) {
#ifdef EAI_SYSTEM
case EAI_SYSTEM: return strerror(errno);
#endif
default: return gai_strerror(err);
default: return LUA_GAI_STRERROR(err);
}
}

0 comments on commit 5a7e3f0

Please sign in to comment.