From 2713255e30a41a22c1cfde2241273ac8ddcccc5a Mon Sep 17 00:00:00 2001 From: On behalf of John Marshall Date: Wed, 23 Sep 2009 10:14:32 +0000 Subject: [PATCH] Suppress bgzf_check_EOF() messages when reading from a pipe, as there is no way to seek on a pipe and the messages always appear. --- bam.c | 7 ++++++- knetfile.c | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bam.c b/bam.c index 619b46a..f6e05ff 100644 --- a/bam.c +++ b/bam.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "bam.h" #include "bam_endian.h" @@ -94,7 +95,11 @@ bam_header_t *bam_header_read(bamFile fp) int32_t i = 1, name_len; // check EOF i = bgzf_check_EOF(fp); - if (i < 0) fprintf(stderr, "[bam_header_read] read from pipe; skip EOF checking.\n"); + if (i < 0) { + // If the file is a pipe, checking the EOF marker will *always* fail + // with ESPIPE. Suppress the error message in this case. + if (errno != ESPIPE) perror("[bam_header_read] bgzf_check_EOF"); + } else if (i == 0) fprintf(stderr, "[bam_header_read] EOF marker is absent.\n"); // read "BAM1" if (bam_read(fp, buf, 4) != 4) return 0; diff --git a/knetfile.c b/knetfile.c index 9e11dcc..4a41e65 100644 --- a/knetfile.c +++ b/knetfile.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -499,7 +500,6 @@ off_t knet_seek(knetFile *fp, off_t off, int whence) * while fseek() returns zero on success. */ off_t offset = lseek(fp->fd, off, whence); if (offset == -1) { - perror("lseek"); return -1; } fp->offset = offset; @@ -520,6 +520,7 @@ off_t knet_seek(knetFile *fp, off_t off, int whence) { if (whence == SEEK_END) { // FIXME: can we allow SEEK_END in future? fprintf(stderr, "[knet_seek] SEEK_END is not supported for HTTP. Offset is unchanged.\n"); + errno = ESPIPE; return -1; } if (whence==SEEK_CUR) @@ -529,6 +530,7 @@ off_t knet_seek(knetFile *fp, off_t off, int whence) fp->is_ready = 0; return fp->offset; } + errno = EINVAL; return -1; } -- 2.39.2