From d5212c13b081ed62d8e1ae436779e79c79edf564 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 4 Jun 2024 12:48:29 -0300 Subject: More disciplined use of 'errno' Set errno to zero before calling any function where we may use its errno, and check errno for zero before using it (as functions may not set it even in error). --- loslib.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'loslib.c') diff --git a/loslib.c b/loslib.c index ad5a9276..ba80d72c 100644 --- a/loslib.c +++ b/loslib.c @@ -155,6 +155,7 @@ static int os_execute (lua_State *L) { static int os_remove (lua_State *L) { const char *filename = luaL_checkstring(L, 1); + errno = 0; return luaL_fileresult(L, remove(filename) == 0, filename); } @@ -162,6 +163,7 @@ static int os_remove (lua_State *L) { static int os_rename (lua_State *L) { const char *fromname = luaL_checkstring(L, 1); const char *toname = luaL_checkstring(L, 2); + errno = 0; return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); } -- cgit v1.2.3-55-g6feb