diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-10-21 17:41:24 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-10-21 17:41:24 -0300 |
commit | 6505503b49c90c069db6ed8ea28b7d1a8c922678 (patch) | |
tree | 870157e65ba6f9af51eb849f104778068258fd0f | |
parent | ec748fcb0a6913a814f106218e9fde3a73ffc014 (diff) | |
download | lua-6505503b49c90c069db6ed8ea28b7d1a8c922678.tar.gz lua-6505503b49c90c069db6ed8ea28b7d1a8c922678.tar.bz2 lua-6505503b49c90c069db6ed8ea28b7d1a8c922678.zip |
do not pretend that file is closed when close fails
-rw-r--r-- | liolib.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.20 2002/10/11 20:40:32 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.21 2002/10/16 20:41:35 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 | */ |
@@ -100,8 +100,12 @@ static int aux_close (lua_State *L) { | |||
100 | FILE *f = tofile(L, 1); | 100 | FILE *f = tofile(L, 1); |
101 | if (f == stdin || f == stdout || f == stderr) | 101 | if (f == stdin || f == stdout || f == stderr) |
102 | return 0; /* file cannot be closed */ | 102 | return 0; /* file cannot be closed */ |
103 | *(FILE **)lua_touserdata(L, 1) = NULL; /* mark file as closed */ | 103 | else { |
104 | return (pclose(f) != -1) || (fclose(f) == 0); | 104 | int ok = (pclose(f) != -1) || (fclose(f) == 0); |
105 | if (ok) | ||
106 | *(FILE **)lua_touserdata(L, 1) = NULL; /* mark file as closed */ | ||
107 | return ok; | ||
108 | } | ||
105 | } | 109 | } |
106 | 110 | ||
107 | 111 | ||