diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-06-23 10:48:39 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-06-23 10:48:39 -0300 |
commit | 88b65da4d7e834b357d99670842e27b9dfde2fb8 (patch) | |
tree | 962f42b1d941b6f5c2c10ab4ff689cea67ad0b36 /liolib.c | |
parent | 521b38532a29ab0590be722712b7c367607e5ba9 (diff) | |
download | lua-88b65da4d7e834b357d99670842e27b9dfde2fb8.tar.gz lua-88b65da4d7e834b357d99670842e27b9dfde2fb8.tar.bz2 lua-88b65da4d7e834b357d99670842e27b9dfde2fb8.zip |
simplifications.
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 27 |
1 files changed, 10 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.39 1999/05/05 19:22:26 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.40 1999/05/14 12:24:04 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 | */ |
@@ -157,9 +157,13 @@ static void setfile (FILE *f, char *name, int tag) { | |||
157 | 157 | ||
158 | 158 | ||
159 | static void setreturn (FILE *f, char *name) { | 159 | static void setreturn (FILE *f, char *name) { |
160 | int tag = gettag(); | 160 | if (f == NULL) |
161 | setfile(f, name, tag); | 161 | pushresult(0); |
162 | lua_pushusertag(f, tag); | 162 | else { |
163 | int tag = gettag(); | ||
164 | setfile(f, name, tag); | ||
165 | lua_pushusertag(f, tag); | ||
166 | } | ||
163 | } | 167 | } |
164 | 168 | ||
165 | 169 | ||
@@ -175,10 +179,6 @@ static void io_readfrom (void) { | |||
175 | else { | 179 | else { |
176 | char *s = luaL_check_string(FIRSTARG); | 180 | char *s = luaL_check_string(FIRSTARG); |
177 | current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); | 181 | current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); |
178 | if (current == NULL) { | ||
179 | pushresult(0); | ||
180 | return; | ||
181 | } | ||
182 | } | 182 | } |
183 | setreturn(current, FINPUT); | 183 | setreturn(current, FINPUT); |
184 | } | 184 | } |
@@ -196,21 +196,14 @@ static void io_writeto (void) { | |||
196 | else { | 196 | else { |
197 | char *s = luaL_check_string(FIRSTARG); | 197 | char *s = luaL_check_string(FIRSTARG); |
198 | current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w"); | 198 | current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w"); |
199 | if (current == NULL) { | ||
200 | pushresult(0); | ||
201 | return; | ||
202 | } | ||
203 | } | 199 | } |
204 | setreturn(current, FOUTPUT); | 200 | setreturn(current, FOUTPUT); |
205 | } | 201 | } |
206 | 202 | ||
207 | 203 | ||
208 | static void io_appendto (void) { | 204 | static void io_appendto (void) { |
209 | FILE *fp = fopen(luaL_check_string(FIRSTARG), "a"); | 205 | FILE *current = fopen(luaL_check_string(FIRSTARG), "a"); |
210 | if (fp != NULL) | 206 | setreturn(current, FOUTPUT); |
211 | setreturn(fp, FOUTPUT); | ||
212 | else | ||
213 | pushresult(0); | ||
214 | } | 207 | } |
215 | 208 | ||
216 | 209 | ||