Skip to content

Commit 099cc47

Browse files
committed
Fix stuff:
a bunch of error handlers couldn't compile under older C standards
1 parent 9116b0c commit 099cc47

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lnn.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ LUALIB_API int luaopen_nn(lua_State *L) {
3232
int value;
3333
const char *name;
3434

35-
for(int n = 0; (name = nn_symbol(n, &value)) != NULL; n++) {
35+
int n = 0;
36+
for(; (name = nn_symbol(n, &value)) != NULL; n++) {
3637
lua_pushinteger(L, value);
3738
lua_setfield(L, -2, name);
3839
}
@@ -180,10 +181,10 @@ static int lnn_socket_recv(lua_State *L) {
180181
int recv_len = nn_recv(s, buf, buf_len, flags);
181182
if(recv_len == -1) {
182183
int err = nn_errno();
183-
if(errno & EAGAIN)
184+
if(err & EAGAIN)
184185
return 0;
185186
else
186-
luaL_error(L, "%s", nn_strerror(nn_errno()));
187+
luaL_error(L, "%s", nn_strerror(err));
187188
}
188189
lua_pushlstring(L, buf, recv_len);
189190

@@ -194,7 +195,7 @@ static int lnn_socket_recv(lua_State *L) {
194195
int recv_len = nn_recv(s, &buf, NN_MSG, flags);
195196
if(recv_len == -1) {
196197
int err = nn_errno();
197-
if(errno & EAGAIN)
198+
if(err & EAGAIN)
198199
return 0;
199200
else
200201
luaL_error(L, "%s", nn_strerror(err));
@@ -217,10 +218,10 @@ static int lnn_socket_send(lua_State *L) {
217218

218219
if(nn_send(s, msg, len, flags) == 1) {
219220
int err = nn_errno();
220-
if(errno & EAGAIN)
221+
if(err & EAGAIN)
221222
return 0;
222223
else
223-
luaL_error(L, "%s", nn_strerror(nn_errno()));
224+
luaL_error(L, "%s", nn_strerror(err));
224225
}
225226

226227
lua_pushinteger(L, len);
@@ -243,6 +244,8 @@ static int lnn_socket_setopt(lua_State *L) {
243244
int ival = luaL_checkinteger(L, 4);
244245
val = (char*) &ival;
245246
len = sizeof(ival);
247+
} else {
248+
return luaL_error(L, "invalid option value: %s", lua_tostring(L, 4));
246249
}
247250

248251
if(nn_setsockopt(s, level, option, val, len) == -1)
@@ -307,7 +310,7 @@ static int lnn_poll_add(lua_State *L) {
307310
struct lnn_poll **ptr = luaL_checkudata(L, 1, LNN_POLL);
308311
struct lnn_poll *poll = *ptr;
309312
int s = *((int*) luaL_checkudata(L, 2, LNN_SOCKET));
310-
bool inp, out = false;
313+
bool inp = false, out = false;
311314
if(lua_gettop(L) >= 3) {
312315
inp = lua_toboolean(L, 3);
313316
if(lua_gettop(L) >= 4) {

0 commit comments

Comments
 (0)