From 5a7e3f08886ef2893148c1342fb6021291cf1307 Mon Sep 17 00:00:00 2001 From: rpatters1 Date: Wed, 27 Jul 2022 01:51:35 -0500 Subject: [PATCH] fix(build): Use gai_strerrorA not gai_strerror on Windows * 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 --- src/inet.c | 4 ++-- src/socket.h | 2 ++ src/udp.c | 4 ++-- src/usocket.c | 2 +- src/wsocket.c | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/inet.c mode change 100644 => 100755 src/socket.h mode change 100644 => 100755 src/udp.c diff --git a/src/inet.c b/src/inet.c old mode 100644 new mode 100755 index ec73fea..138c9ab --- a/src/inet.c +++ b/src/inet.c @@ -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); @@ -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); diff --git a/src/socket.h b/src/socket.h old mode 100644 new mode 100755 index e541f27..2555bab --- a/src/socket.h +++ b/src/socket.h @@ -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 /*=========================================================================*\ diff --git a/src/udp.c b/src/udp.c old mode 100644 new mode 100755 index 62b6a20..712ad50 --- a/src/udp.c +++ b/src/udp.c @@ -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; } @@ -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; } diff --git a/src/usocket.c b/src/usocket.c index acfe186..69635da 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -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); } } diff --git a/src/wsocket.c b/src/wsocket.c index 7cd4115..6cb1e41 100755 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -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); } }