]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - tools/perf/util/zlib.c
1 // SPDX-License-Identifier: GPL-2.0
8 #include "util/compress.h"
10 #include "util/debug.h"
13 #define CHUNK_SIZE 16384
15 int gzip_decompress_to_file(const char *input
, int output_fd
)
17 int ret
= Z_STREAM_ERROR
;
22 unsigned char buf
[CHUNK_SIZE
];
31 input_fd
= open(input
, O_RDONLY
);
35 if (fstat(input_fd
, &stbuf
) < 0)
38 ptr
= mmap(NULL
, stbuf
.st_size
, PROT_READ
, MAP_PRIVATE
, input_fd
, 0);
39 if (ptr
== MAP_FAILED
)
42 if (inflateInit2(&zs
, 16 + MAX_WBITS
) != Z_OK
)
46 zs
.avail_in
= stbuf
.st_size
;
50 zs
.avail_out
= CHUNK_SIZE
;
52 ret
= inflate(&zs
, Z_NO_FLUSH
);
64 len
= CHUNK_SIZE
- zs
.avail_out
;
65 if (writen(output_fd
, buf
, len
) != len
) {
70 } while (ret
!= Z_STREAM_END
);
75 munmap(ptr
, stbuf
.st_size
);
79 return ret
== Z_STREAM_END
? 0 : -1;