8 #include "util/debug.h"
11 #define CHUNK_SIZE 16384
13 int gzip_decompress_to_file(const char *input
, int output_fd
)
15 int ret
= Z_STREAM_ERROR
;
20 unsigned char buf
[CHUNK_SIZE
];
29 input_fd
= open(input
, O_RDONLY
);
33 if (fstat(input_fd
, &stbuf
) < 0)
36 ptr
= mmap(NULL
, stbuf
.st_size
, PROT_READ
, MAP_PRIVATE
, input_fd
, 0);
37 if (ptr
== MAP_FAILED
)
40 if (inflateInit2(&zs
, 16 + MAX_WBITS
) != Z_OK
)
44 zs
.avail_in
= stbuf
.st_size
;
48 zs
.avail_out
= CHUNK_SIZE
;
50 ret
= inflate(&zs
, Z_NO_FLUSH
);
62 len
= CHUNK_SIZE
- zs
.avail_out
;
63 if (writen(output_fd
, buf
, len
) != len
) {
68 } while (ret
!= Z_STREAM_END
);
73 munmap(ptr
, stbuf
.st_size
);
77 return ret
== Z_STREAM_END
? 0 : -1;