Skip to content

Commit 4b57fd4

Browse files
olsajiriacmel
authored andcommitted
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>
1 parent 8b42b7e commit 4b57fd4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tools/perf/util/lzma.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
#include <lzma.h>
44
#include <stdio.h>
55
#include <linux/compiler.h>
6+
#include <sys/types.h>
7+
#include <sys/stat.h>
8+
#include <fcntl.h>
69
#include "compress.h"
710
#include "util.h"
811
#include "debug.h"
12+
#include <unistd.h>
913

1014
#define BUFSIZE 8192
1115

@@ -100,7 +104,18 @@ int lzma_decompress_to_file(const char *input, int output_fd)
100104
return err;
101105
}
102106

103-
bool lzma_is_compressed(const char *input __maybe_unused)
107+
bool lzma_is_compressed(const char *input)
104108
{
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;
106121
}

0 commit comments

Comments
 (0)