diff options
| -rw-r--r-- | lauxlib.c | 2 | ||||
| -rw-r--r-- | liolib.c | 1 | ||||
| -rw-r--r-- | loslib.c | 6 |
3 files changed, 6 insertions, 3 deletions
| @@ -284,7 +284,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { | |||
| 284 | 284 | ||
| 285 | LUALIB_API int luaL_execresult (lua_State *L, int stat) { | 285 | LUALIB_API int luaL_execresult (lua_State *L, int stat) { |
| 286 | const char *what = "exit"; /* type of termination */ | 286 | const char *what = "exit"; /* type of termination */ |
| 287 | if (stat == -1) /* error? */ | 287 | if (stat != 0 && errno != 0) /* error with an 'errno'? */ |
| 288 | return luaL_fileresult(L, 0, NULL); | 288 | return luaL_fileresult(L, 0, NULL); |
| 289 | else { | 289 | else { |
| 290 | l_inspectstat(stat, what); /* interpret result */ | 290 | l_inspectstat(stat, what); /* interpret result */ |
| @@ -270,6 +270,7 @@ static int io_open (lua_State *L) { | |||
| 270 | */ | 270 | */ |
| 271 | static int io_pclose (lua_State *L) { | 271 | static int io_pclose (lua_State *L) { |
| 272 | LStream *p = tolstream(L); | 272 | LStream *p = tolstream(L); |
| 273 | errno = 0; | ||
| 273 | return luaL_execresult(L, l_pclose(L, p->f)); | 274 | return luaL_execresult(L, l_pclose(L, p->f)); |
| 274 | } | 275 | } |
| 275 | 276 | ||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "lprefix.h" | 10 | #include "lprefix.h" |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | #include <errno.h> | ||
| 13 | #include <locale.h> | 14 | #include <locale.h> |
| 14 | #include <stdlib.h> | 15 | #include <stdlib.h> |
| 15 | #include <string.h> | 16 | #include <string.h> |
| @@ -138,10 +139,11 @@ | |||
| 138 | 139 | ||
| 139 | 140 | ||
| 140 | 141 | ||
| 141 | |||
| 142 | static int os_execute (lua_State *L) { | 142 | static int os_execute (lua_State *L) { |
| 143 | const char *cmd = luaL_optstring(L, 1, NULL); | 143 | const char *cmd = luaL_optstring(L, 1, NULL); |
| 144 | int stat = system(cmd); | 144 | int stat; |
| 145 | errno = 0; | ||
| 146 | stat = system(cmd); | ||
| 145 | if (cmd != NULL) | 147 | if (cmd != NULL) |
| 146 | return luaL_execresult(L, stat); | 148 | return luaL_execresult(L, stat); |
| 147 | else { | 149 | else { |
