Restore zoulas fixes, stages 2.

This commit is contained in:
Arnold D. Robbins 2020-02-06 22:32:55 +02:00
parent 5068d20ef6
commit cd552112a7
1 changed files with 30 additions and 29 deletions

59
run.c
View File

@ -1817,35 +1817,36 @@ const char *filename(FILE *fp)
return "???"; return "???";
} }
Cell *closefile(Node **a, int n) Cell *closefile(Node **a, int n)
{ {
Cell *x; Cell *x;
int i, stat; size_t i;
bool stat;
x = execute(a[0]);
getsval(x); x = execute(a[0]);
stat = -1; getsval(x);
for (i = 0; i < nfiles; i++) { stat = true;
if (files[i].fname && strcmp(x->sval, files[i].fname) == 0) { for (i = 0; i < nfiles; i++) {
if (ferror(files[i].fp)) if (!files[i].fname || strcmp(x->sval, files[i].fname) != 0)
FATAL( "i/o error occurred on %s", files[i].fname ); continue;
if (files[i].mode == '|' || files[i].mode == LE) if (ferror(files[i].fp))
stat = pclose(files[i].fp); FATAL("i/o error occurred on %s", files[i].fname);
else if (files[i].mode == '|' || files[i].mode == LE)
stat = fclose(files[i].fp); stat = pclose(files[i].fp) == -1;
if (stat == EOF) else
FATAL( "i/o error occurred closing %s", files[i].fname ); stat = fclose(files[i].fp) == EOF;
if (i > 2) /* don't do /dev/std... */ if (stat)
xfree(files[i].fname); FATAL("i/o error occurred closing %s", files[i].fname);
files[i].fname = NULL; /* watch out for ref thru this */ if (i > 2) /* don't do /dev/std... */
files[i].fp = NULL; xfree(files[i].fname);
} files[i].fname = NULL; /* watch out for ref thru this */
} files[i].fp = NULL;
tempfree(x); }
x = gettemp(); tempfree(x);
setfval(x, (Awkfloat) stat); x = gettemp();
return(x); setfval(x, (Awkfloat) (stat ? -1 : 0));
} return(x);
}
void closeall(void) void closeall(void)
{ {