]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/perf/util/lzma.c
4 #include <linux/compiler.h>
11 static const char *lzma_strerror(lzma_ret ret
)
15 return "Memory allocation failed";
16 case LZMA_OPTIONS_ERROR
:
17 return "Unsupported decompressor flags";
18 case LZMA_FORMAT_ERROR
:
19 return "The input is not in the .xz format";
21 return "Compressed file is corrupt";
23 return "Compressed file is truncated or otherwise corrupt";
25 return "Unknown error, possibly a bug";
29 int lzma_decompress_to_file(const char *input
, int output_fd
)
31 lzma_action action
= LZMA_RUN
;
32 lzma_stream strm
= LZMA_STREAM_INIT
;
40 infile
= fopen(input
, "rb");
42 pr_err("lzma: fopen failed on %s: '%s'\n",
43 input
, strerror(errno
));
47 ret
= lzma_stream_decoder(&strm
, UINT64_MAX
, LZMA_CONCATENATED
);
49 pr_err("lzma: lzma_stream_decoder failed %s (%d)\n",
50 lzma_strerror(ret
), ret
);
56 strm
.next_out
= buf_out
;
57 strm
.avail_out
= sizeof(buf_out
);
60 if (strm
.avail_in
== 0 && !feof(infile
)) {
61 strm
.next_in
= buf_in
;
62 strm
.avail_in
= fread(buf_in
, 1, sizeof(buf_in
), infile
);
65 pr_err("lzma: read error: %s\n", strerror(errno
));
73 ret
= lzma_code(&strm
, action
);
75 if (strm
.avail_out
== 0 || ret
== LZMA_STREAM_END
) {
76 ssize_t write_size
= sizeof(buf_out
) - strm
.avail_out
;
78 if (writen(output_fd
, buf_out
, write_size
) != write_size
) {
79 pr_err("lzma: write error: %s\n", strerror(errno
));
83 strm
.next_out
= buf_out
;
84 strm
.avail_out
= sizeof(buf_out
);
88 if (ret
== LZMA_STREAM_END
)
91 pr_err("lzma: failed %s\n", lzma_strerror(ret
));