summaryrefslogtreecommitdiff
path: root/src/lib_os.c
diff options
context:
space:
mode:
authorMike Pall <mike>2012-09-24 19:00:54 +0200
committerMike Pall <mike>2012-09-24 19:00:54 +0200
commitcfca926cc2e2b63e94492f0a1f5c033f6db3a6f5 (patch)
tree4601d6b067fcea09b9e1368b998baa1b48de4866 /src/lib_os.c
parent125cc879884b19ffa9181b7a52d1b7b73759301e (diff)
downloadluajit-cfca926cc2e2b63e94492f0a1f5c033f6db3a6f5.tar.gz
luajit-cfca926cc2e2b63e94492f0a1f5c033f6db3a6f5.tar.bz2
luajit-cfca926cc2e2b63e94492f0a1f5c033f6db3a6f5.zip
From Lua 5.2: Extended results from os.execute() and pipe:close().
Needs -DLUAJIT_ENABLE_LUA52COMPAT.
Diffstat (limited to '')
-rw-r--r--src/lib_os.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/lib_os.c b/src/lib_os.c
index 2412d47b..21774975 100644
--- a/src/lib_os.c
+++ b/src/lib_os.c
@@ -31,41 +31,41 @@
31 31
32#define LJLIB_MODULE_os 32#define LJLIB_MODULE_os
33 33
34static int os_pushresult(lua_State *L, int i, const char *filename)
35{
36 int en = errno; /* calls to Lua API may change this value */
37 if (i) {
38 setboolV(L->top-1, 1);
39 return 1;
40 } else {
41 setnilV(L->top-1);
42 lua_pushfstring(L, "%s: %s", filename, strerror(en));
43 lua_pushinteger(L, en);
44 return 3;
45 }
46}
47
48LJLIB_CF(os_execute) 34LJLIB_CF(os_execute)
49{ 35{
50#if LJ_TARGET_CONSOLE 36#if LJ_TARGET_CONSOLE
37#if LJ_52
38 errno = ENOSYS;
39 return luaL_fileresult(L, 0, NULL);
40#else
51 lua_pushinteger(L, -1); 41 lua_pushinteger(L, -1);
42 return 1;
43#endif
52#else 44#else
53 lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); 45 const char *cmd = luaL_optstring(L, 1, NULL);
46 int stat = system(cmd);
47#if LJ_52
48 if (cmd)
49 return luaL_execresult(L, stat);
50 setboolV(L->top++, 1);
51#else
52 setintV(L->top++, stat);
54#endif 53#endif
55 return 1; 54 return 1;
55#endif
56} 56}
57 57
58LJLIB_CF(os_remove) 58LJLIB_CF(os_remove)
59{ 59{
60 const char *filename = luaL_checkstring(L, 1); 60 const char *filename = luaL_checkstring(L, 1);
61 return os_pushresult(L, remove(filename) == 0, filename); 61 return luaL_fileresult(L, remove(filename) == 0, filename);
62} 62}
63 63
64LJLIB_CF(os_rename) 64LJLIB_CF(os_rename)
65{ 65{
66 const char *fromname = luaL_checkstring(L, 1); 66 const char *fromname = luaL_checkstring(L, 1);
67 const char *toname = luaL_checkstring(L, 2); 67 const char *toname = luaL_checkstring(L, 2);
68 return os_pushresult(L, rename(fromname, toname) == 0, fromname); 68 return luaL_fileresult(L, rename(fromname, toname) == 0, fromname);
69} 69}
70 70
71LJLIB_CF(os_tmpname) 71LJLIB_CF(os_tmpname)