1
0
spogulis no https://git.tukaani.org/xz.git synced 2025-09-18 08:28:24 +00:00

Windows: Avoid an error message on broken pipe

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
Šī revīzija ir iekļauta:
Lasse Collin 2025-01-28 16:28:18 +02:00
vecāks 95b638480a
revīzija 4d7e7c9d94
Šim parakstam datu bāzē netika atrasta zināma atslēga
GPG atslēgas ID: 38EE757D69184620
2 mainīti faili ar 23 papildinājumiem un 1 dzēšanām

Parādīt failu

@ -1390,6 +1390,19 @@ io_write_buf(file_pair *pair, const uint8_t *buf, size_t size)
} }
#endif #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 // Handle broken pipe specially. gzip and bzip2
// don't print anything on SIGPIPE. In addition, // don't print anything on SIGPIPE. In addition,
// gzip --quiet uses exit status 2 (warning) on // gzip --quiet uses exit status 2 (warning) on

Parādīt failu

@ -230,8 +230,17 @@ uncompress(lzma_stream *strm, FILE *file, const char *filename)
// Wouldn't be a surprise if writing to stderr // Wouldn't be a surprise if writing to stderr
// would fail too but at least try to show an // would fail too but at least try to show an
// error message. // 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)); "%s", strerror(errno));
}
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }