aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2021-12-01 22:46:18 +0200
committerArnold D. Robbins <arnold@skeeve.com>2021-12-01 22:46:18 +0200
commit0521e672efdbfdaedabfacca03c7a535b4f8526c (patch)
tree96c5db398195d2b81d66a891fae0848b97bfe87d /io.c
parenta22095c81a677b82accccb53cab91052cdc0cbfe (diff)
parentf77e1318c515d495ac9c08bdfdf2dadf79a9649f (diff)
downloadegawk-0521e672efdbfdaedabfacca03c7a535b4f8526c.tar.gz
egawk-0521e672efdbfdaedabfacca03c7a535b4f8526c.tar.bz2
egawk-0521e672efdbfdaedabfacca03c7a535b4f8526c.zip
Merge branch 'gawk-5.1-stable'
Diffstat (limited to 'io.c')
-rw-r--r--io.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/io.c b/io.c
index 91c94d9b..0da8699e 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 */
@@ -1460,10 +1463,8 @@ non_fatal_flush_std_file(FILE *fp)
bool is_fatal = ! is_non_fatal_std(fp);
if (is_fatal) {
-#ifdef __MINGW32__
- if (errno == 0 || errno == EINVAL)
- w32_maybe_set_errno();
-#endif
+ os_maybe_set_errno();
+
if (errno == EPIPE)
die_via_sigpipe();
else
@@ -1560,10 +1561,8 @@ close_io(bool *stdio_problem, bool *got_EPIPE)
*stdio_problem = false;
/* we don't warn about stdout/stderr if EPIPE, but we do error exit */
if (fflush(stdout) != 0) {
-#ifdef __MINGW32__
- if (errno == 0 || errno == EINVAL)
- w32_maybe_set_errno();
-#endif
+ os_maybe_set_errno();
+
if (errno != EPIPE)
warning(_("error writing standard output: %s"), strerror(errno));
else
@@ -1573,10 +1572,8 @@ close_io(bool *stdio_problem, bool *got_EPIPE)
*stdio_problem = true;
}
if (fflush(stderr) != 0) {
-#ifdef __MINGW32__
- if (errno == 0 || errno == EINVAL)
- w32_maybe_set_errno();
-#endif
+ os_maybe_set_errno();
+
if (errno != EPIPE)
warning(_("error writing standard error: %s"), strerror(errno));
else