From: On behalf of John Marshall Date: Mon, 30 Nov 2009 12:09:04 +0000 (+0000) Subject: Index files should be opened in binary mode, not text mode. X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;ds=sidebyside;h=185ac166fd66907c8435f4d371582c972695bd4c;p=samtools.git Index files should be opened in binary mode, not text mode. --- diff --git a/bam_index.c b/bam_index.c index a627884..853ac70 100644 --- a/bam_index.c +++ b/bam_index.c @@ -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);