[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-88c74dc76a30b9242c2df687deb44788d93fee6b@git.kernel.org>
Date: Thu, 23 Aug 2018 01:44:54 -0700
From: tip-bot for Jiri Olsa <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: hpa@...or.com, namhyung@...nel.org, jolsa@...nel.org,
mpetlan@...hat.com, acme@...hat.com, tglx@...utronix.de,
linux-kernel@...r.kernel.org, alexander.shishkin@...ux.intel.com,
mingo@...nel.org, dsahern@...il.com, peterz@...radead.org
Subject: [tip:perf/urgent] perf tools: Add gzip_is_compressed function
Commit-ID: 88c74dc76a30b9242c2df687deb44788d93fee6b
Gitweb: https://git.kernel.org/tip/88c74dc76a30b9242c2df687deb44788d93fee6b
Author: Jiri Olsa <jolsa@...nel.org>
AuthorDate: Fri, 17 Aug 2018 11:48:12 +0200
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Mon, 20 Aug 2018 08:54:59 -0300
perf tools: Add gzip_is_compressed function
Add implementation of the is_compressed callback for gzip.
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Michael Petlan <mpetlan@...hat.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Link: http://lkml.kernel.org/r/20180817094813.15086-13-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/util/zlib.c | 16 ++++++++++++++--
1 file 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;
}
Powered by blists - more mailing lists