summaryrefslogtreecommitdiff
path: root/src/htszlib.c
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-07-10 16:25:50 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-07-10 16:25:50 +0000
commit942bebf4b29cbae800614df17d9d4af650a8d3ba (patch)
tree30a7562f433d51999aa251446d1b1ece1deec959 /src/htszlib.c
parente4b71bb7d41a7daab67322a567c6ddafafe383fa (diff)
Fixed uncompressing
Diffstat (limited to 'src/htszlib.c')
-rw-r--r--src/htszlib.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/htszlib.c b/src/htszlib.c
index f78d778..47cb53c 100644
--- a/src/htszlib.c
+++ b/src/htszlib.c
@@ -56,10 +56,11 @@ int hts_zunpack(char *filename, char *newfile) {
int ret = -1;
char catbuff[CATBUFF_SIZE];
- if (filename && newfile) {
+ if (filename != NULL && newfile != NULL) {
if (filename[0] && newfile[0]) {
- // not: NOT an UTF-8 filename
- gzFile gz = gzopen(filename, "rb");
+ FILE *const in = FOPEN(fconv(catbuff, filename), "rb");
+ const int fd_in = in != NULL ? fileno(in) : -1;
+ gzFile gz = gzdopen(fd_in, "rb");
if (gz) {
FILE *const fpout = FOPEN(fconv(catbuff, newfile), "wb");
@@ -71,7 +72,7 @@ int hts_zunpack(char *filename, char *newfile) {
do {
char BIGSTK buff[1024];
- nr = gzread(gz, buff, 1024);
+ nr = gzread(gz, buff, sizeof(buff));
if (nr > 0) {
size += nr;
if (fwrite(buff, 1, nr, fpout) != nr)
@@ -84,6 +85,9 @@ int hts_zunpack(char *filename, char *newfile) {
gzclose(gz);
ret = (int) size;
}
+ if (in != NULL) {
+ fclose(in);
+ }
}
}
return ret;