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

57
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]); x = execute(a[0]);
getsval(x); getsval(x);
stat = -1; stat = true;
for (i = 0; i < nfiles; i++) { for (i = 0; i < nfiles; i++) {
if (files[i].fname && strcmp(x->sval, files[i].fname) == 0) { if (!files[i].fname || strcmp(x->sval, files[i].fname) != 0)
if (ferror(files[i].fp)) continue;
FATAL( "i/o error occurred on %s", files[i].fname ); if (ferror(files[i].fp))
if (files[i].mode == '|' || files[i].mode == LE) FATAL("i/o error occurred on %s", files[i].fname);
stat = pclose(files[i].fp); if (files[i].mode == '|' || files[i].mode == LE)
else stat = pclose(files[i].fp) == -1;
stat = fclose(files[i].fp); else
if (stat == EOF) stat = fclose(files[i].fp) == EOF;
FATAL( "i/o error occurred closing %s", files[i].fname ); if (stat)
if (i > 2) /* don't do /dev/std... */ FATAL("i/o error occurred closing %s", files[i].fname);
xfree(files[i].fname); if (i > 2) /* don't do /dev/std... */
files[i].fname = NULL; /* watch out for ref thru this */ xfree(files[i].fname);
files[i].fp = NULL; files[i].fname = NULL; /* watch out for ref thru this */
} files[i].fp = NULL;
} }
tempfree(x); tempfree(x);
x = gettemp(); x = gettemp();
setfval(x, (Awkfloat) stat); setfval(x, (Awkfloat) (stat ? -1 : 0));
return(x); return(x);
} }
void closeall(void) void closeall(void)
{ {