aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/lzma.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/lzma.c')
-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 @@
3#include <lzma.h> 3#include <lzma.h>
4#include <stdio.h> 4#include <stdio.h>
5#include <linux/compiler.h> 5#include <linux/compiler.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <fcntl.h>
6#include "compress.h" 9#include "compress.h"
7#include "util.h" 10#include "util.h"
8#include "debug.h" 11#include "debug.h"
12#include <unistd.h>
9 13
10#define BUFSIZE 8192 14#define BUFSIZE 8192
11 15
@@ -100,7 +104,18 @@ err_fclose:
100 return err; 104 return err;
101} 105}
102 106
103bool lzma_is_compressed(const char *input __maybe_unused) 107bool lzma_is_compressed(const char *input)
104{ 108{
105 return true; 109 int fd = open(input, O_RDONLY);
110 const uint8_t magic[6] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 };
111 char buf[6] = { 0 };
112 ssize_t rc;
113
114 if (fd < 0)
115 return -1;
116
117 rc = read(fd, buf, sizeof(buf));
118 close(fd);
119 return rc == sizeof(buf) ?
120 memcmp(buf, magic, sizeof(buf)) == 0 : false;
106} 121}