]> git.donarmstrong.com Git - samtools.git/commitdiff
Index files should be opened in binary mode, not text mode.
authorOn behalf of John Marshall <lh3@sanger.ac.uk>
Mon, 30 Nov 2009 12:09:04 +0000 (12:09 +0000)
committerOn behalf of John Marshall <lh3@sanger.ac.uk>
Mon, 30 Nov 2009 12:09:04 +0000 (12:09 +0000)
bam_index.c

index a6278843583c605799360affb0b9c3c21fbd02c4..853ac705fc9bef5a653ab9aae9eb9100ec551e12 100644 (file)
@@ -339,13 +339,13 @@ bam_index_t *bam_index_load_local(const char *_fn)
        } else fn = strdup(_fn);
        fnidx = (char*)calloc(strlen(fn) + 5, 1);
        strcpy(fnidx, fn); strcat(fnidx, ".bai");
-       fp = fopen(fnidx, "r");
+       fp = fopen(fnidx, "rb");
        if (fp == 0) { // try "{base}.bai"
                char *s = strstr(fn, "bam");
                if (s == fn + strlen(fn) - 3) {
                        strcpy(fnidx, fn);
                        fnidx[strlen(fn)-1] = 'i';
-                       fp = fopen(fnidx, "r");
+                       fp = fopen(fnidx, "rb");
                }
        }
        free(fnidx); free(fn);
@@ -375,7 +375,7 @@ static void download_from_remote(const char *url)
                fprintf(stderr, "[download_from_remote] fail to open remote file.\n");
                return;
        }
-       if ((fp = fopen(fn, "w")) == 0) {
+       if ((fp = fopen(fn, "wb")) == 0) {
                fprintf(stderr, "[download_from_remote] fail to create file in the working directory.\n");
                knet_close(fp_remote);
                return;
@@ -425,7 +425,7 @@ int bam_index_build2(const char *fn, const char *_fnidx)
                fnidx = (char*)calloc(strlen(fn) + 5, 1);
                strcpy(fnidx, fn); strcat(fnidx, ".bai");
        } else fnidx = strdup(_fnidx);
-       fpidx = fopen(fnidx, "w");
+       fpidx = fopen(fnidx, "wb");
        if (fpidx == 0) {
                fprintf(stderr, "[bam_index_build2] fail to create the index file.\n");
                free(fnidx);