aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-04-06 06:00:28 +0300
committerArnold D. Robbins <arnold@skeeve.com>2016-04-06 06:00:28 +0300
commit62342b5ad8522da5cbc0623f2b645c48b31c2838 (patch)
tree71cef270090969e33b68825dfa003efc25ff5602 /builtin.c
parent525d6122c57db7b5f193b1fc22dc680a44f6c962 (diff)
parent43a645fe05c57576d9d41a7f3b18bb55b1dbdc3e (diff)
downloadegawk-62342b5ad8522da5cbc0623f2b645c48b31c2838.tar.gz
egawk-62342b5ad8522da5cbc0623f2b645c48b31c2838.tar.bz2
egawk-62342b5ad8522da5cbc0623f2b645c48b31c2838.zip
Merge branch 'master' into feature/cmake
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/builtin.c b/builtin.c
index 9bd8e5eb..e07bdb53 100644
--- a/builtin.c
+++ b/builtin.c
@@ -241,6 +241,9 @@ do_fflush(int nargs)
fp = rp->output.fp;
if (fp != NULL)
status = rp->output.gawk_fflush(fp, rp->output.opaque);
+ else if ((rp->flag & RED_TWOWAY) != 0)
+ warning(_("fflush: cannot flush: two-way pipe `%s' has closed write end"),
+ file);
} else if ((fp = stdfile(tmp->stptr, tmp->stlen)) != NULL) {
status = fflush(fp);
} else {
@@ -1674,8 +1677,16 @@ do_printf(int nargs, int redirtype)
if (redir_exp->type != Node_val)
fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp));
rp = redirect(redir_exp, redirtype, & errflg, true);
- if (rp != NULL)
+ if (rp != NULL) {
+ if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) {
+ if (is_non_fatal_redirect(redir_exp->stptr)) {
+ update_ERRNO_int(EBADF);
+ return;
+ }
+ fatal(_("printf: attempt to write to closed write end of two-way pipe"));
+ }
fp = rp->output.fp;
+ }
else if (errflg) {
update_ERRNO_int(errflg);
return;
@@ -2150,8 +2161,16 @@ do_print(int nargs, int redirtype)
if (redir_exp->type != Node_val)
fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp));
rp = redirect(redir_exp, redirtype, & errflg, true);
- if (rp != NULL)
+ if (rp != NULL) {
+ if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) {
+ if (is_non_fatal_redirect(redir_exp->stptr)) {
+ update_ERRNO_int(EBADF);
+ return;
+ }
+ fatal(_("print: attempt to write to closed write end of two-way pipe"));
+ }
fp = rp->output.fp;
+ }
else if (errflg) {
update_ERRNO_int(errflg);
return;
@@ -2220,8 +2239,16 @@ do_print_rec(int nargs, int redirtype)
if (redirtype != 0) {
redir_exp = TOP();
rp = redirect(redir_exp, redirtype, & errflg, true);
- if (rp != NULL)
+ if (rp != NULL) {
+ if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) {
+ if (is_non_fatal_redirect(redir_exp->stptr)) {
+ update_ERRNO_int(EBADF);
+ return;
+ }
+ fatal(_("print: attempt to write to closed write end of two-way pipe"));
+ }
fp = rp->output.fp;
+ }
DEREF(redir_exp);
decr_sp();
} else