aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2021-11-30 15:15:20 -0500
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2021-11-30 15:15:20 -0500
commit9eb357e008385176a44b695e6117f95b2ea104a7 (patch)
tree84c94e9ff50ca39b3e139c1dc3c7d1310903bd5a /io.c
parent5870bfcddf538fac3b87b65abc716d34766d94cf (diff)
downloadegawk-9eb357e008385176a44b695e6117f95b2ea104a7.tar.gz
egawk-9eb357e008385176a44b695e6117f95b2ea104a7.tar.bz2
egawk-9eb357e008385176a44b695e6117f95b2ea104a7.zip
Flush output to redirections before closing to detect output errors.
Diffstat (limited to 'io.c')
-rw-r--r--io.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/io.c b/io.c
index 91c94d9b..bcaff3c3 100644
--- a/io.c
+++ b/io.c
@@ -1375,6 +1375,9 @@ close_redir(struct redirect *rp, bool exitwarn, two_way_close_type how)
if (rp == NULL)
return 0;
+ if ((rp->flag & RED_WRITE) && rp->output.fp)
+ /* flush before closing to leverage special error handling */
+ efflush(rp->output.fp, "flush", rp);
if (rp->output.fp == stdout || rp->output.fp == stderr)
goto checkwarn; /* bypass closing, remove from list */