1
0
의 미러 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
This commit is contained in:
Lasse Collin 2025-01-28 16:28:18 +02:00
부모 95b638480a
커밋 4d7e7c9d94
No known key found for this signature in database
GPG 키 ID: 38EE757D69184620
2개의 변경된 파일23개의 추가작업 그리고 1개의 파일을 삭제

파일 보기

@ -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

파일 보기

@ -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);
} }