'luaL_execresult' does not assume -1 status as error
ISO C is silent about the return of 'system'. Windows sets 'errno' in case of errors. Linux has several different error cases, with different return values. ISO C allows 'system' to set 'errno' even if there are no errors. Here we assume that a status==0 is success (which is the case on several platforms), otherwise it is an error. If there is an error number, gives the error based on it. (The worst a spurious 'errno' can do is to generate a bad error message.) Otherwise uses the normal results.
This commit is contained in:
6
loslib.c
6
loslib.c
@@ -10,6 +10,7 @@
|
||||
#include "lprefix.h"
|
||||
|
||||
|
||||
#include <errno.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -138,10 +139,11 @@
|
||||
|
||||
|
||||
|
||||
|
||||
static int os_execute (lua_State *L) {
|
||||
const char *cmd = luaL_optstring(L, 1, NULL);
|
||||
int stat = system(cmd);
|
||||
int stat;
|
||||
errno = 0;
|
||||
stat = system(cmd);
|
||||
if (cmd != NULL)
|
||||
return luaL_execresult(L, stat);
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user