aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/net.c
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-06-07 02:25:56 +0200
committerKim Alvefur <zash@zash.se>2020-06-07 02:25:56 +0200
commit625ec0a93f194fa152b0cf0b94f60afdee224df9 (patch)
treef547a1c5e6015d76b345f21ea6707f48bc716b26 /util-src/net.c
parentb50db460865f3f0a1b1dbad90ee3bc5fbcec3a8f (diff)
downloadprosody-625ec0a93f194fa152b0cf0b94f60afdee224df9.tar.gz
prosody-625ec0a93f194fa152b0cf0b94f60afdee224df9.zip
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Actually just an alias of pushnil, but it does make it more obvious where the failure conditions are, which is good for readability.
Diffstat (limited to 'util-src/net.c')
-rw-r--r--util-src/net.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/util-src/net.c b/util-src/net.c
index c3b07815..d786e885 100644
--- a/util-src/net.c
+++ b/util-src/net.c
@@ -33,6 +33,9 @@
#if (LUA_VERSION_NUM == 501)
#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
#endif
+#if (LUA_VERSION_NUM < 504)
+#define luaL_pushfail lua_pushnil
+#endif
/* Enumerate all locally configured IP addresses */
@@ -59,7 +62,7 @@ static int lc_local_addresses(lua_State *L) {
#ifndef _WIN32
if(getifaddrs(&addr) < 0) {
- lua_pushnil(L);
+ luaL_pushfail(L);
lua_pushfstring(L, "getifaddrs failed (%d): %s", errno,
strerror(errno));
return 2;
@@ -141,14 +144,14 @@ static int lc_pton(lua_State *L) {
case -1:
errno_ = errno;
- lua_pushnil(L);
+ luaL_pushfail(L);
lua_pushstring(L, strerror(errno_));
lua_pushinteger(L, errno_);
return 3;
default:
case 0:
- lua_pushnil(L);
+ luaL_pushfail(L);
lua_pushstring(L, strerror(EINVAL));
lua_pushinteger(L, EINVAL);
return 3;
@@ -170,7 +173,7 @@ static int lc_ntop(lua_State *L) {
family = AF_INET;
}
else {
- lua_pushnil(L);
+ luaL_pushfail(L);
lua_pushstring(L, strerror(EAFNOSUPPORT));
lua_pushinteger(L, EAFNOSUPPORT);
return 3;
@@ -179,7 +182,7 @@ static int lc_ntop(lua_State *L) {
if(!inet_ntop(family, ipaddr, buf, INET6_ADDRSTRLEN))
{
errno_ = errno;
- lua_pushnil(L);
+ luaL_pushfail(L);
lua_pushstring(L, strerror(errno_));
lua_pushinteger(L, errno_);
return 3;