diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2016-04-06 06:00:28 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2016-04-06 06:00:28 +0300 |
commit | 62342b5ad8522da5cbc0623f2b645c48b31c2838 (patch) | |
tree | 71cef270090969e33b68825dfa003efc25ff5602 /builtin.c | |
parent | 525d6122c57db7b5f193b1fc22dc680a44f6c962 (diff) | |
parent | 43a645fe05c57576d9d41a7f3b18bb55b1dbdc3e (diff) | |
download | egawk-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.c | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -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 |