Skip to content

Commit

Permalink
Revert "Patched STDIN input reading: now input is read as soon as pos…
Browse files Browse the repository at this point in the history
…sible"

This reverts commit 245d850.
  • Loading branch information
circulosmeos committed Jul 20, 2022
1 parent 656470b commit b052a07
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions gztool.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
#include <sys/stat.h> // stat()
#include <math.h> // pow()
#include <stdbool.h>// bool, false, true
#include <sys/ioctl.h>// ioctl()

// sets binary mode for stdin in Windows
#define STDIN 0
Expand Down Expand Up @@ -2403,36 +2402,9 @@ local struct returned_output decompress_and_build_index(
// note that here strm.avail_in > 0 only if ret.error == Z_STREAM_END
int strm_avail_in0 = strm.avail_in;
if ( !feof( file_in ) ) { // on last block, strm.avail_in > 0 is possible with feof(file_in)==1 already!

if ( strlen( file_name ) == 0 ) { // read from STDIN:
// do not wait for the buffer to be complete (<=CHUNK), but read asap
int n = 0;
strm.avail_in = 0;

if ( ioctl(0, FIONREAD, &n) >= 0 && n > 0 ) {
if ( ( CHUNK - strm_avail_in0 ) >= n ) {
strm.avail_in = fread(input + strm_avail_in0, 1, n, file_in);
} else {
strm.avail_in = fread(input + strm_avail_in0, 1, CHUNK - strm_avail_in0, file_in);
}
} else {
// sometimes ioctl() on STDIN doesn't immediatly return data there on &n ...
if ( EXTRACT_TAIL == indx_n_extraction_opts ) { // (this is the more affected option,
// as it doesn't loop here again)
// so make usual fread() until complete the whole chunk size:
// (a while(ioctl()) loop here, waiting for input is not feasible, as window2 (code is executed)
// later, and an (infinite) waiting loop here would prevent its output for being printed)
strm.avail_in = fread(input + strm_avail_in0, 1, CHUNK - strm_avail_in0, file_in);
}
}

} else { // read from file
strm.avail_in = fread(input + strm_avail_in0, 1, CHUNK - strm_avail_in0, file_in);
}

strm.avail_in = fread(input + strm_avail_in0, 1, CHUNK - strm_avail_in0, file_in);
printToStderr( VERBOSITY_MANIAC, "[read %d B]", strm.avail_in );
strm.avail_in += strm_avail_in0;

}
if ( feof( file_in ) ) {
// generic check for growing files (not related to bgzip-compatible-streams code):
Expand Down

0 comments on commit b052a07

Please sign in to comment.