diff options
author | Jiri Olsa <jolsa@kernel.org> | 2018-08-17 05:48:12 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-08-20 07:54:59 -0400 |
commit | 88c74dc76a30b9242c2df687deb44788d93fee6b (patch) | |
tree | 046152361e4aef1d86a7bb377d60cbff0d033040 | |
parent | 4b57fd44b61beb51b7d64f21c72941ba10c1ea2b (diff) |
perf tools: Add gzip_is_compressed function
Add implementation of the is_compressed callback for gzip.
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-13-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/zlib.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c index e68317214679..902ce6384f57 100644 --- a/tools/perf/util/zlib.c +++ b/tools/perf/util/zlib.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <sys/mman.h> | 6 | #include <sys/mman.h> |
7 | #include <zlib.h> | 7 | #include <zlib.h> |
8 | #include <linux/compiler.h> | 8 | #include <linux/compiler.h> |
9 | #include <unistd.h> | ||
9 | 10 | ||
10 | #include "util/compress.h" | 11 | #include "util/compress.h" |
11 | #include "util/util.h" | 12 | #include "util/util.h" |
@@ -81,7 +82,18 @@ out_close: | |||
81 | return ret == Z_STREAM_END ? 0 : -1; | 82 | return ret == Z_STREAM_END ? 0 : -1; |
82 | } | 83 | } |
83 | 84 | ||
84 | bool gzip_is_compressed(const char *input __maybe_unused) | 85 | bool gzip_is_compressed(const char *input) |
85 | { | 86 | { |
86 | return true; | 87 | int fd = open(input, O_RDONLY); |
88 | const uint8_t magic[2] = { 0x1f, 0x8b }; | ||
89 | char buf[2] = { 0 }; | ||
90 | ssize_t rc; | ||
91 | |||
92 | if (fd < 0) | ||
93 | return -1; | ||
94 | |||
95 | rc = read(fd, buf, sizeof(buf)); | ||
96 | close(fd); | ||
97 | return rc == sizeof(buf) ? | ||
98 | memcmp(buf, magic, sizeof(buf)) == 0 : false; | ||
87 | } | 99 | } |