From 88b65da4d7e834b357d99670842e27b9dfde2fb8 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 23 Jun 1999 10:48:39 -0300 Subject: simplifications. --- liolib.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/liolib.c b/liolib.c index 63a698d1..edc0f25e 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 1.39 1999/05/05 19:22:26 roberto Exp roberto $ +** $Id: liolib.c,v 1.40 1999/05/14 12:24:04 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -157,9 +157,13 @@ static void setfile (FILE *f, char *name, int tag) { static void setreturn (FILE *f, char *name) { - int tag = gettag(); - setfile(f, name, tag); - lua_pushusertag(f, tag); + if (f == NULL) + pushresult(0); + else { + int tag = gettag(); + setfile(f, name, tag); + lua_pushusertag(f, tag); + } } @@ -175,10 +179,6 @@ static void io_readfrom (void) { else { char *s = luaL_check_string(FIRSTARG); current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); - if (current == NULL) { - pushresult(0); - return; - } } setreturn(current, FINPUT); } @@ -196,21 +196,14 @@ static void io_writeto (void) { else { char *s = luaL_check_string(FIRSTARG); current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w"); - if (current == NULL) { - pushresult(0); - return; - } } setreturn(current, FOUTPUT); } static void io_appendto (void) { - FILE *fp = fopen(luaL_check_string(FIRSTARG), "a"); - if (fp != NULL) - setreturn(fp, FOUTPUT); - else - pushresult(0); + FILE *current = fopen(luaL_check_string(FIRSTARG), "a"); + setreturn(current, FOUTPUT); } -- cgit v1.2.3-55-g6feb