Commit 88c74dc7 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf tools: Add gzip_is_compressed function

Add implementation of the is_compressed callback for gzip.
Signed-off-by: default avatarJiri 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4b57fd44
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <zlib.h> #include <zlib.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <unistd.h>
#include "util/compress.h" #include "util/compress.h"
#include "util/util.h" #include "util/util.h"
...@@ -81,7 +82,18 @@ int gzip_decompress_to_file(const char *input, int output_fd) ...@@ -81,7 +82,18 @@ int gzip_decompress_to_file(const char *input, int output_fd)
return ret == Z_STREAM_END ? 0 : -1; 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;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment