summaryrefslogtreecommitdiff
path: root/Src/builtin.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 08be1acdd..e093cbe32 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4527,7 +4527,8 @@ bin_print(char *name, char **args, Options ops, int func)
if (OPT_ISSET(ops,'z') || OPT_ISSET(ops,'s')) {
#ifdef HAVE_OPEN_MEMSTREAM
putc(0, fout);
- fflush(fout);
+ fclose(fout);
+ fout = NULL;
#else
rewind(fout);
buf = (char *)zalloc(count + 1);
@@ -4548,11 +4549,16 @@ bin_print(char *name, char **args, Options ops, int func)
unqueue_signals();
}
- /* Testing EBADF special-cases >&- redirections */
- if ((fout != stdout) ? (fclose(fout) != 0) :
- (fflush(fout) != 0 && errno != EBADF)) {
- zwarnnam(name, "write error: %e", errno);
- ret = 1;
+#ifdef HAVE_OPEN_MEMSTREAM
+ if (fout)
+#endif
+ {
+ /* Testing EBADF special-cases >&- redirections */
+ if ((fout != stdout) ? (fclose(fout) != 0) :
+ (fflush(fout) != 0 && errno != EBADF)) {
+ zwarnnam(name, "write error: %e", errno);
+ ret = 1;
+ }
}
return ret;
}