summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2018-08-17 11:48:11 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-08-20 08:54:59 -0300
commit4b57fd44b61beb51b7d64f21c72941ba10c1ea2b (patch)
treeff38853a10133407fa0be8d2948ae4499f45f77a /tools
parent8b42b7e5e8b5692bc5e57342bf00c40d64978407 (diff)
downloadlinux-stable-4b57fd44b61beb51b7d64f21c72941ba10c1ea2b.tar.gz
linux-stable-4b57fd44b61beb51b7d64f21c72941ba10c1ea2b.tar.bz2
linux-stable-4b57fd44b61beb51b7d64f21c72941ba10c1ea2b.zip
perf tools: Add lzma_is_compressed function
Add implementation of the is_compressed callback for lzma. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180817094813.15086-12-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/lzma.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c
index 7032caaf75eb..b1dd29a9d915 100644
--- a/tools/perf/util/lzma.c
+++ b/tools/perf/util/lzma.c
@@ -3,9 +3,13 @@
#include <lzma.h>
#include <stdio.h>
#include <linux/compiler.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "compress.h"
#include "util.h"
#include "debug.h"
+#include <unistd.h>
#define BUFSIZE 8192
@@ -100,7 +104,18 @@ err_fclose:
return err;
}
-bool lzma_is_compressed(const char *input __maybe_unused)
+bool lzma_is_compressed(const char *input)
{
- return true;
+ int fd = open(input, O_RDONLY);
+ const uint8_t magic[6] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 };
+ char buf[6] = { 0 };
+ ssize_t rc;
+
+ if (fd < 0)
+ return -1;
+
+ rc = read(fd, buf, sizeof(buf));
+ close(fd);
+ return rc == sizeof(buf) ?
+ memcmp(buf, magic, sizeof(buf)) == 0 : false;
}