version 1.70, 2021/11/01 18:28:24 |
version 1.71, 2022/01/27 16:58:37 |
|
|
return "???"; |
return "???"; |
} |
} |
|
|
Cell *closefile(Node **a, int n) |
Cell *closefile(Node **a, int n) |
{ |
{ |
Cell *x; |
Cell *x; |
size_t i; |
size_t i; |
bool stat; |
bool stat; |
|
|
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) |
continue; |
continue; |
if (ferror(files[i].fp)) |
if (files[i].mode == GT || files[i].mode == '|') |
FATAL("i/o error occurred on %s", files[i].fname); |
fflush(files[i].fp); |
|
if (ferror(files[i].fp)) { |
|
if ((files[i].mode == GT && files[i].fp != stderr) |
|
|| files[i].mode == '|') |
|
FATAL("write error on %s", files[i].fname); |
|
else |
|
WARNING("i/o error occurred on %s", files[i].fname); |
|
} |
if (files[i].fp == stdin || files[i].fp == stdout || |
if (files[i].fp == stdin || files[i].fp == stdout || |
files[i].fp == stderr) |
files[i].fp == stderr) |
stat = freopen("/dev/null", "r+", files[i].fp) == NULL; |
stat = freopen("/dev/null", "r+", files[i].fp) == NULL; |
|
|
else |
else |
stat = fclose(files[i].fp) == EOF; |
stat = fclose(files[i].fp) == EOF; |
if (stat) |
if (stat) |
FATAL("i/o error occurred closing %s", files[i].fname); |
WARNING("i/o error occurred closing %s", files[i].fname); |
if (i > 2) /* don't do /dev/std... */ |
if (i > 2) /* don't do /dev/std... */ |
xfree(files[i].fname); |
xfree(files[i].fname); |
files[i].fname = NULL; /* watch out for ref thru this */ |
files[i].fname = NULL; /* watch out for ref thru this */ |
|
|
x = gettemp(); |
x = gettemp(); |
setfval(x, (Awkfloat) (stat ? -1 : 0)); |
setfval(x, (Awkfloat) (stat ? -1 : 0)); |
return(x); |
return(x); |
} |
} |
|
|
void closeall(void) |
void closeall(void) |
{ |
{ |
|
|
for (i = 0; i < nfiles; i++) { |
for (i = 0; i < nfiles; i++) { |
if (! files[i].fp) |
if (! files[i].fp) |
continue; |
continue; |
if (ferror(files[i].fp)) |
if (files[i].mode == GT || files[i].mode == '|') |
FATAL( "i/o error occurred on %s", files[i].fname ); |
fflush(files[i].fp); |
if (files[i].fp == stdin) |
if (ferror(files[i].fp)) { |
|
if ((files[i].mode == GT && files[i].fp != stderr) |
|
|| files[i].mode == '|') |
|
FATAL("write error on %s", files[i].fname); |
|
else |
|
WARNING("i/o error occurred on %s", files[i].fname); |
|
} |
|
if (files[i].fp == stdin || files[i].fp == stdout || |
|
files[i].fp == stderr) |
continue; |
continue; |
if (files[i].mode == '|' || files[i].mode == LE) |
if (files[i].mode == '|' || files[i].mode == LE) |
stat = pclose(files[i].fp) == -1; |
stat = pclose(files[i].fp) == -1; |
else if (files[i].fp == stdout || files[i].fp == stderr) |
|
stat = fflush(files[i].fp) == EOF; |
|
else |
else |
stat = fclose(files[i].fp) == EOF; |
stat = fclose(files[i].fp) == EOF; |
if (stat) |
if (stat) |
FATAL( "i/o error occurred while closing %s", files[i].fname ); |
WARNING("i/o error occurred while closing %s", files[i].fname); |
} |
} |
} |
} |
|
|