diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2022-01-27 16:58:38 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2022-01-27 16:58:38 +0000 |
commit | 2c36c83ee15dd3f136155d5f866415691d0acf11 (patch) | |
tree | d85ebe8876d71cca09c7b3f467a1127b15eb1216 /usr.bin/awk/run.c | |
parent | c9e131110141b714133f7a23612504acb1b61af2 (diff) |
Update awk to Dec 8, 2021 version.
Fixes error handling in closefile() and closeall(). Long standing
warnings had been made fatal and some fatal errors went undetected.
Diffstat (limited to 'usr.bin/awk/run.c')
-rw-r--r-- | usr.bin/awk/run.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 128a7eaead6..1a86cec5fea 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.70 2021/11/01 18:28:24 millert Exp $ */ +/* $OpenBSD: run.c,v 1.71 2022/01/27 16:58:37 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -1984,8 +1984,8 @@ const char *filename(FILE *fp) return "???"; } - Cell *closefile(Node **a, int n) - { +Cell *closefile(Node **a, int n) +{ Cell *x; size_t i; bool stat; @@ -1996,8 +1996,15 @@ const char *filename(FILE *fp) for (i = 0; i < nfiles; i++) { if (!files[i].fname || strcmp(x->sval, files[i].fname) != 0) continue; - if (ferror(files[i].fp)) - FATAL("i/o error occurred on %s", files[i].fname); + if (files[i].mode == GT || files[i].mode == '|') + 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 || files[i].fp == stderr) stat = freopen("/dev/null", "r+", files[i].fp) == NULL; @@ -2006,7 +2013,7 @@ const char *filename(FILE *fp) else stat = fclose(files[i].fp) == EOF; 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... */ xfree(files[i].fname); files[i].fname = NULL; /* watch out for ref thru this */ @@ -2017,7 +2024,7 @@ const char *filename(FILE *fp) x = gettemp(); setfval(x, (Awkfloat) (stat ? -1 : 0)); return(x); - } +} void closeall(void) { @@ -2027,18 +2034,24 @@ void closeall(void) for (i = 0; i < nfiles; i++) { if (! files[i].fp) continue; - if (ferror(files[i].fp)) - FATAL( "i/o error occurred on %s", files[i].fname ); - if (files[i].fp == stdin) + if (files[i].mode == GT || files[i].mode == '|') + 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 || + files[i].fp == stderr) continue; if (files[i].mode == '|' || files[i].mode == LE) stat = pclose(files[i].fp) == -1; - else if (files[i].fp == stdout || files[i].fp == stderr) - stat = fflush(files[i].fp) == EOF; else stat = fclose(files[i].fp) == EOF; if (stat) - FATAL( "i/o error occurred while closing %s", files[i].fname ); + WARNING("i/o error occurred while closing %s", files[i].fname); } } |