X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=tabix.git;a=blobdiff_plain;f=bgzip.c;h=5429a22cac00ffa8c437ccffc75f6143e8eed553;hp=d144632c64a1f7b8f7ce2d060c49a680e50f7915;hb=HEAD;hpb=c70c92b7a385548d8e670638a93a083401f49e4d diff --git a/bgzip.c b/bgzip.c index d144632..5429a22 100644 --- a/bgzip.c +++ b/bgzip.c @@ -72,7 +72,7 @@ static int write_open(const char *fn, int is_forced) static void fail(BGZF* fp) { - fprintf(stderr, "Error: %s\n", fp->error); + fprintf(stderr, "Error: %d\n", fp->errcode); exit(1); } @@ -132,13 +132,13 @@ int main(int argc, char **argv) else if (!pstdout && isatty(fileno((FILE *)stdout)) ) return bgzip_main_usage(); - fp = bgzf_fdopen(f_dst, "w"); + fp = bgzf_dopen(f_dst, "w"); buffer = malloc(WINDOW_SIZE); while ((c = read(f_src, buffer, WINDOW_SIZE)) > 0) if (bgzf_write(fp, buffer, c) < 0) fail(fp); // f_dst will be closed here if (bgzf_close(fp) < 0) fail(fp); - if (argc > optind) unlink(argv[optind]); + if (argc > optind && !pstdout) unlink(argv[optind]); free(buffer); close(f_src); return 0; @@ -166,17 +166,22 @@ int main(int argc, char **argv) return 1; } - name = strdup(argv[optind]); - name[strlen(name) - 3] = '\0'; - f_dst = write_open(name, is_forced); - free(name); + if (pstdout) { + f_dst = fileno(stdout); + } + else { + name = strdup(argv[optind]); + name[strlen(name) - 3] = '\0'; + f_dst = write_open(name, is_forced); + free(name); + } } else if (!pstdout && isatty(fileno((FILE *)stdin)) ) return bgzip_main_usage(); else { f_dst = fileno(stdout); - fp = bgzf_fdopen(fileno(stdin), "r"); + fp = bgzf_dopen(fileno(stdin), "r"); if (fp == NULL) { fprintf(stderr, "[bgzip] Could not read from stdin: %s\n", strerror(errno)); return 1;