diff options
Diffstat (limited to 'Src')
-rw-r--r-- | Src/builtin.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Src/builtin.c b/Src/builtin.c index cbc69b599..b51f61e27 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3031,9 +3031,11 @@ bin_print(char *name, char **args, char *ops, int func) } while (*ap); fputc(ops['N'] ? '\0' : '\n', fout); } - if (((fout != stdout) ? fclose(fout) : fflush(fout)) != 0) { - zwarnnam(name, "write error: %e", NULL, errno); - ret = 1; + /* Testing EBADF special-cases >&- redirections */ + if ((fout != stdout) ? (fclose(fout) != 0) : + (fflush(fout) != 0 && errno != EBADF)) { + zwarnnam(name, "write error: %e", NULL, errno); + ret = 1; } return ret; } @@ -3045,7 +3047,9 @@ bin_print(char *name, char **args, char *ops, int func) } if (!(ops['n'] || nnl)) fputc(ops['N'] ? '\0' : '\n', fout); - if (((fout != stdout) ? fclose(fout) : fflush(fout)) != 0) { + /* Testing EBADF special-cases >&- redirections */ + if ((fout != stdout) ? (fclose(fout) != 0) : + (fflush(fout) != 0 && errno != EBADF)) { zwarnnam(name, "write error: %e", NULL, errno); ret = 1; } |