aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-02-20 10:50:27 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-02-20 10:50:27 -0300
commite39e758a73c08953d477c8e024ffbd1e2edfe6a5 (patch)
tree6d710ebf5278bc10ab085076c4fb13fe9fb280b9
parent5438d77221e5f909b2f1990721ec56ec352b932b (diff)
downloadlua-e39e758a73c08953d477c8e024ffbd1e2edfe6a5.tar.gz
lua-e39e758a73c08953d477c8e024ffbd1e2edfe6a5.tar.bz2
lua-e39e758a73c08953d477c8e024ffbd1e2edfe6a5.zip
closing a "popen" file returns the process exit status
-rw-r--r--liolib.c11
-rw-r--r--luaconf.h8
2 files changed, 12 insertions, 7 deletions
diff --git a/liolib.c b/liolib.c
index 4895283f..1978c510 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.78 2008/02/12 16:51:03 roberto Exp roberto $ 2** $Id: liolib.c,v 2.79 2008/02/12 17:05:36 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -106,9 +106,14 @@ static int io_noclose (lua_State *L) {
106*/ 106*/
107static int io_pclose (lua_State *L) { 107static int io_pclose (lua_State *L) {
108 FILE **p = tofilep(L); 108 FILE **p = tofilep(L);
109 int ok = lua_pclose(L, *p); 109 int stat = lua_pclose(L, *p);
110 *p = NULL; 110 *p = NULL;
111 return pushresult(L, ok, NULL); 111 if (stat == -1) /* error? */
112 return pushresult(L, 0, NULL);
113 else {
114 lua_pushinteger(L, stat);
115 return 1; /* return status */
116 }
112} 117}
113 118
114 119
diff --git a/luaconf.h b/luaconf.h
index 9fb62b67..9da44ea5 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.101 2009/02/07 12:23:15 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.102 2009/02/18 13:17:10 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -695,18 +695,18 @@ union luai_Cast { double l_d; long l_l; };
695#if defined(LUA_USE_POPEN) 695#if defined(LUA_USE_POPEN)
696 696
697#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) 697#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
698#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) 698#define lua_pclose(L,file) ((void)L, pclose(file))
699 699
700#elif defined(LUA_WIN) 700#elif defined(LUA_WIN)
701 701
702#define lua_popen(L,c,m) ((void)L, _popen(c,m)) 702#define lua_popen(L,c,m) ((void)L, _popen(c,m))
703#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) 703#define lua_pclose(L,file) ((void)L, _pclose(file))
704 704
705#else 705#else
706 706
707#define lua_popen(L,c,m) ((void)((void)c, m), \ 707#define lua_popen(L,c,m) ((void)((void)c, m), \
708 luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) 708 luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
709#define lua_pclose(L,file) ((void)((void)L, file), 0) 709#define lua_pclose(L,file) ((void)((void)L, file), -1)
710 710
711#endif 711#endif
712 712