Skip to content

Commit

Permalink
Avoid bgzf EOF check on modern MinGW releases.
Browse files Browse the repository at this point in the history
Unfortunately this test is proving unreliable now following a change
to lseek so that it no longer returns -1 on pipes.

Fixes samtools/bcftools#1901
  • Loading branch information
jkbonfield committed Apr 11, 2023
1 parent a616e85 commit ba89d9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions bgzf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,15 @@ int bgzf_mt_read_block(BGZF *fp, bgzf_job *j)

static int bgzf_check_EOF_common(BGZF *fp)
{
#if defined(__MINGW32__) && HTS_GCC_AT_LEAST(12, 0)
// Modern MinGW appears to have started returning non-zero values from
// lseek when the file descriptor is a pipe. It thinks SEEK_END is the
// size of the pipe buffer. It doesn't set errno to ESPIPE either.

// See also test/test_bgzf.c test_check_EOF()
return 2;
#endif

uint8_t buf[28];
off_t offset = htell(fp->fp);
if (hseek(fp->fp, -28, SEEK_END) < 0) {
Expand Down
5 changes: 3 additions & 2 deletions test/test_bgzf.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,17 @@ static int test_index_load_dump(Files *f) {

static int test_check_EOF(char *name, int expected) {
BGZF *bgz = try_bgzf_open(name, "r", __func__);
int eof;
if (!bgz) return -1;
eof = bgzf_check_EOF(bgz);
#if !(defined(__MINGW32__) && HTS_GCC_AT_LEAST(12, 0))
int eof = bgzf_check_EOF(bgz);
if (eof != expected) {
fprintf(stderr, "%s : Unexpected result %d from bgzf_check_EOF on %s; "
"expected %d\n",
__func__, eof, name, expected);
bgzf_close(bgz);
return -1;
}
#endif

return try_bgzf_close(&bgz, name, __func__, 0);
}
Expand Down

0 comments on commit ba89d9d

Please sign in to comment.