diff options
Diffstat (limited to 'tools/perf/util/lzma.c')
| -rw-r--r-- | tools/perf/util/lzma.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c index b1dd29a9d915..c355757ed391 100644 --- a/tools/perf/util/lzma.c +++ b/tools/perf/util/lzma.c @@ -7,9 +7,10 @@ #include <sys/stat.h> #include <fcntl.h> #include "compress.h" -#include "util.h" #include "debug.h" +#include <string.h> #include <unistd.h> +#include <internal/lib.h> #define BUFSIZE 8192 @@ -31,7 +32,7 @@ static const char *lzma_strerror(lzma_ret ret) } } -int lzma_decompress_to_file(const char *input, int output_fd) +int lzma_decompress_stream_to_file(FILE *infile, int output_fd) { lzma_action action = LZMA_RUN; lzma_stream strm = LZMA_STREAM_INIT; @@ -40,20 +41,11 @@ int lzma_decompress_to_file(const char *input, int output_fd) u8 buf_in[BUFSIZE]; u8 buf_out[BUFSIZE]; - FILE *infile; - - infile = fopen(input, "rb"); - if (!infile) { - pr_err("lzma: fopen failed on %s: '%s'\n", - input, strerror(errno)); - return -1; - } ret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED); if (ret != LZMA_OK) { - pr_err("lzma: lzma_stream_decoder failed %s (%d)\n", - lzma_strerror(ret), ret); - goto err_fclose; + pr_debug("lzma: lzma_stream_decoder failed %s (%d)\n", lzma_strerror(ret), ret); + return err; } strm.next_in = NULL; @@ -67,8 +59,8 @@ int lzma_decompress_to_file(const char *input, int output_fd) strm.avail_in = fread(buf_in, 1, sizeof(buf_in), infile); if (ferror(infile)) { - pr_err("lzma: read error: %s\n", strerror(errno)); - goto err_fclose; + pr_debug("lzma: read error: %s\n", strerror(errno)); + goto err_lzma_end; } if (feof(infile)) @@ -81,8 +73,8 @@ int lzma_decompress_to_file(const char *input, int output_fd) ssize_t write_size = sizeof(buf_out) - strm.avail_out; if (writen(output_fd, buf_out, write_size) != write_size) { - pr_err("lzma: write error: %s\n", strerror(errno)); - goto err_fclose; + pr_debug("lzma: write error: %s\n", strerror(errno)); + goto err_lzma_end; } strm.next_out = buf_out; @@ -93,17 +85,33 @@ int lzma_decompress_to_file(const char *input, int output_fd) if (ret == LZMA_STREAM_END) break; - pr_err("lzma: failed %s\n", lzma_strerror(ret)); - goto err_fclose; + pr_debug("lzma: failed %s\n", lzma_strerror(ret)); + goto err_lzma_end; } } err = 0; -err_fclose: - fclose(infile); +err_lzma_end: + lzma_end(&strm); return err; } +int lzma_decompress_to_file(const char *input, int output_fd) +{ + FILE *infile; + int ret; + + infile = fopen(input, "rb"); + if (!infile) { + pr_debug("lzma: fopen failed on %s: '%s'\n", input, strerror(errno)); + return -1; + } + + ret = lzma_decompress_stream_to_file(infile, output_fd); + fclose(infile); + return ret; +} + bool lzma_is_compressed(const char *input) { int fd = open(input, O_RDONLY); @@ -112,7 +120,7 @@ bool lzma_is_compressed(const char *input) ssize_t rc; if (fd < 0) - return -1; + return false; rc = read(fd, buf, sizeof(buf)); close(fd); |
