diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-04 12:48:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-04 12:48:29 -0300 |
commit | d5212c13b081ed62d8e1ae436779e79c79edf564 (patch) | |
tree | 936ac196173318f51bec43077a2006ef48a88813 /loslib.c | |
parent | e0efebdbe4e4053c6fb78588c546f1dc23aa964a (diff) | |
download | lua-d5212c13b081ed62d8e1ae436779e79c79edf564.tar.gz lua-d5212c13b081ed62d8e1ae436779e79c79edf564.tar.bz2 lua-d5212c13b081ed62d8e1ae436779e79c79edf564.zip |
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).
Diffstat (limited to 'loslib.c')
-rw-r--r-- | loslib.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -155,6 +155,7 @@ static int os_execute (lua_State *L) { | |||
155 | 155 | ||
156 | static int os_remove (lua_State *L) { | 156 | static int os_remove (lua_State *L) { |
157 | const char *filename = luaL_checkstring(L, 1); | 157 | const char *filename = luaL_checkstring(L, 1); |
158 | errno = 0; | ||
158 | return luaL_fileresult(L, remove(filename) == 0, filename); | 159 | return luaL_fileresult(L, remove(filename) == 0, filename); |
159 | } | 160 | } |
160 | 161 | ||
@@ -162,6 +163,7 @@ static int os_remove (lua_State *L) { | |||
162 | static int os_rename (lua_State *L) { | 163 | static int os_rename (lua_State *L) { |
163 | const char *fromname = luaL_checkstring(L, 1); | 164 | const char *fromname = luaL_checkstring(L, 1); |
164 | const char *toname = luaL_checkstring(L, 2); | 165 | const char *toname = luaL_checkstring(L, 2); |
166 | errno = 0; | ||
165 | return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); | 167 | return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); |
166 | } | 168 | } |
167 | 169 | ||