Skip to content

Commit

Permalink
Fix bgzip.exe and bcftools.exe handling large files and stdin/stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
xied75 committed Oct 25, 2012
1 parent 000b0da commit 08a430b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions bcftools/index.c
Expand Up @@ -206,7 +206,7 @@ static void download_from_remote(const char *url)

static char *get_local_version(const char *fn)
{
struct stat sbuf;
struct __stat64 sbuf;
char *fnidx = (char*)calloc(strlen(fn) + 5, 1);
strcat(strcpy(fnidx, fn), ".bci");
if ((strstr(fnidx, "ftp://") == fnidx || strstr(fnidx, "http://") == fnidx)) {
Expand All @@ -215,15 +215,15 @@ static char *get_local_version(const char *fn)
for (p = fnidx + l - 1; p >= fnidx; --p)
if (*p == '/') break;
url = fnidx; fnidx = strdup(p + 1);
if (stat(fnidx, &sbuf) == 0) {
if (_stat64(fnidx, &sbuf) == 0) {
free(url);
return fnidx;
}
fprintf(stderr, "[%s] downloading the index file...\n", __FUNCTION__);
download_from_remote(url);
free(url);
}
if (stat(fnidx, &sbuf) == 0) return fnidx;
if (_stat64(fnidx, &sbuf) == 0) return fnidx;
free(fnidx); return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions bcftools/main.c
Expand Up @@ -24,13 +24,13 @@ int bcf_cat(int n, char * const *fn)
bcf_t *in;
bcf_hdr_t *h;
off_t end;
struct stat s;
struct __stat64 s;
in = bcf_open(fn[i], "r");
h = bcf_hdr_read(in);
if (i == 0) bcf_hdr_write(out, h);
bcf_hdr_destroy(h);
#ifdef _USE_KNETFILE
fstat(knet_fileno(in->fp->x.fpr), &s);
_fstat64(knet_fileno(in->fp->x.fpr), &s);
end = s.st_size - 28;
while (knet_tell(in->fp->x.fpr) < end) {
int size = knet_tell(in->fp->x.fpr) + BUF_SIZE < end? BUF_SIZE : end - knet_tell(in->fp->x.fpr);
Expand Down
13 changes: 8 additions & 5 deletions bgzip.c
Expand Up @@ -87,6 +87,9 @@ int main(int argc, char **argv)
long start, end, size;

_set_fmode(O_BINARY); //dong code, verify
_setmode(_fileno(stdout), O_BINARY);
_setmode(_fileno(stdin), O_BINARY);

compress = 1; pstdout = 0; start = 0; size = -1; end = -1; is_forced = 0;
while((c = getopt(argc, argv, "cdhfb:s:")) >= 0){
switch(c){
Expand All @@ -104,13 +107,13 @@ int main(int argc, char **argv)
return 1;
}
if (compress == 1) {
struct stat sbuf;
struct __stat64 sbuf;
int f_src = _fileno(stdin);
int f_dst = _fileno(stdout);

if ( argc>optind )
{
if ( stat(argv[optind],&sbuf)<0 )
if ( _stat64(argv[optind],&sbuf)<0 )
{
fprintf(stderr, "[bgzip] %s: %s\n", strerror(errno), argv[optind]);
return 1;
Expand All @@ -122,7 +125,7 @@ int main(int argc, char **argv)
}

if (pstdout)
f_dst = _fileno(stdout);
f_dst = _fileno(stdout); //redundant code, dong
else
{
char *name = malloc(strlen(argv[optind]) + 5);
Expand All @@ -147,14 +150,14 @@ int main(int argc, char **argv)
_close(f_src);
return 0;
} else {
struct stat sbuf;
struct __stat64 sbuf;
int f_dst;

if ( argc>optind )
{
char *name;
int len;
if ( stat(argv[optind],&sbuf)<0 )
if ( _stat64(argv[optind],&sbuf)<0 )
{
fprintf(stderr, "[bgzip] %s: %s\n", strerror(errno), argv[optind]);
return 1;
Expand Down

0 comments on commit 08a430b

Please sign in to comment.