]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - tools/perf/util/zlib.c
7 #include "util/compress.h"
9 #include "util/debug.h"
12 #define CHUNK_SIZE 16384
14 int gzip_decompress_to_file(const char *input
, int output_fd
)
16 int ret
= Z_STREAM_ERROR
;
21 unsigned char buf
[CHUNK_SIZE
];
30 input_fd
= open(input
, O_RDONLY
);
34 if (fstat(input_fd
, &stbuf
) < 0)
37 ptr
= mmap(NULL
, stbuf
.st_size
, PROT_READ
, MAP_PRIVATE
, input_fd
, 0);
38 if (ptr
== MAP_FAILED
)
41 if (inflateInit2(&zs
, 16 + MAX_WBITS
) != Z_OK
)
45 zs
.avail_in
= stbuf
.st_size
;
49 zs
.avail_out
= CHUNK_SIZE
;
51 ret
= inflate(&zs
, Z_NO_FLUSH
);
63 len
= CHUNK_SIZE
- zs
.avail_out
;
64 if (writen(output_fd
, buf
, len
) != len
) {
69 } while (ret
!= Z_STREAM_END
);
74 munmap(ptr
, stbuf
.st_size
);
78 return ret
== Z_STREAM_END
? 0 : -1;