Skip to content

Commit

Permalink
[fix] Use isattay instead of poll with 100ms timeout to determine whe…
Browse files Browse the repository at this point in the history
…ther rapidgzip is piped to

Else, bugs can be reproduced easily with:

    ( sleep 1; cat foo.gz ) | src/tools/rapidgzip -d -P 1

and there even is a real use case for this: aws-cli, which
understandibly can take a while until the S3/HTTP request gets
fulfilled.
  • Loading branch information
mxmlnkn committed Feb 14, 2024
1 parent 661ee8a commit 974f0c3
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/core/FileUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@
[[nodiscard]] inline bool
stdinHasInput()
{
const auto handle = GetStdHandle( STD_INPUT_HANDLE );
DWORD bytesAvailable{ 0 };
const auto success = PeekNamedPipe( handle, nullptr, 0, nullptr, &bytesAvailable, nullptr );
return ( success == 0 ) && ( bytesAvailable > 0 );
return _isatty( _fileno( stdin ) ) == 0;
}


Expand All @@ -80,10 +77,7 @@ stdoutIsDevNull()
[[nodiscard]] inline bool
stdinHasInput()
{
pollfd fds{};
fds.fd = STDIN_FILENO;
fds.events = POLLIN;
return poll( &fds, 1, /* timeout in ms */ 100 ) == 1;
return isatty( STDIN_FILENO ) == 0;
}


Expand Down

0 comments on commit 974f0c3

Please sign in to comment.