Also make xz not process more input files after a broken pipe has
been detected. This matches the behavior on POSIX. If all files
are being written to standard output, trying with the next file is
pointless when it's known that standard output won't accept more data.
xzdec already stopped after the first error. It does so with all
errors, so it differs from xz:
$ xz -dc not_found_1 not_found_2
xz: not_found_1: No such file or directory
xz: not_found_2: No such file or directory
$ xzdec not_found_1 not_found_2
xzdec: not_found_1: No such file or directory
Reported-by: Vincent Torri
}
#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ // On native Windows, broken pipe is reported as
+ // EINVAL. Don't show an error message in this case.
+ // Try: xz -dc bigfile.xz | head -n1
+ if (errno == EINVAL
+ && pair->dest_fd == STDOUT_FILENO) {
+ // Emulate SIGPIPE by setting user_abort here.
+ user_abort = true;
+ set_exit_status(E_ERROR);
+ return true;
+ }
+#endif
+
// Handle broken pipe specially. gzip and bzip2
// don't print anything on SIGPIPE. In addition,
// gzip --quiet uses exit status 2 (warning) on
// Wouldn't be a surprise if writing to stderr
// would fail too but at least try to show an
// error message.
- my_errorf("Cannot write to standard output: "
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ // On native Windows, broken pipe is reported
+ // as EINVAL. Don't show an error message
+ // in this case.
+ if (errno != EINVAL)
+#endif
+ {
+ my_errorf("Cannot write to "
+ "standard output: "
"%s", strerror(errno));
+ }
exit(EXIT_FAILURE);
}