]> git.donarmstrong.com Git - samtools.git/commitdiff
Suppress bgzf_check_EOF() messages when reading from a pipe, as there is
authorOn behalf of John Marshall <lh3@sanger.ac.uk>
Wed, 23 Sep 2009 10:14:32 +0000 (10:14 +0000)
committerOn behalf of John Marshall <lh3@sanger.ac.uk>
Wed, 23 Sep 2009 10:14:32 +0000 (10:14 +0000)
no way to seek on a pipe and the messages always appear.

bam.c
knetfile.c

diff --git a/bam.c b/bam.c
index 619b46a6718a773aa073e7ecede13ef5cd10dee8..f6e05ff4285ef6743387e33942b91c91bf0e85fc 100644 (file)
--- a/bam.c
+++ b/bam.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <ctype.h>
+#include <errno.h>
 #include <assert.h>
 #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;
index 9e11dcc19ed71d42bab4ae47f480b81382602fc9..4a41e6576c534abd8b0384ed6e55569d38dc6f50 100644 (file)
@@ -34,6 +34,7 @@
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include <unistd.h>
 #include <sys/types.h>
 
@@ -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;
 }