diff options
author | Jiri Olsa <[email protected]> | 2018-08-17 11:48:12 +0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <[email protected]> | 2018-08-20 08:54:59 -0300 |
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 <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-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 @@ #include <sys/mman.h> #include <zlib.h> #include <linux/compiler.h> +#include <unistd.h> #include "util/compress.h" #include "util/util.h" @@ -81,7 +82,18 @@ out_close: return ret == Z_STREAM_END ? 0 : -1; } -bool gzip_is_compressed(const char *input __maybe_unused) +bool gzip_is_compressed(const char *input) { - return true; + int fd = open(input, O_RDONLY); + const uint8_t magic[2] = { 0x1f, 0x8b }; + char buf[2] = { 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; } |