mirror of
https://gitee.com/openharmony/kernel_linux
synced 2025-05-20 05:36:41 +00:00
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>
This commit is contained in:
parent
8b42b7e5e8
commit
4b57fd44b6
@ -3,9 +3,13 @@
|
|||||||
#include <lzma.h>
|
#include <lzma.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <linux/compiler.h>
|
#include <linux/compiler.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include "compress.h"
|
#include "compress.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define BUFSIZE 8192
|
#define BUFSIZE 8192
|
||||||
|
|
||||||
@ -100,7 +104,18 @@ err_fclose:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lzma_is_compressed(const char *input __maybe_unused)
|
bool lzma_is_compressed(const char *input)
|
||||||
{
|
{
|
||||||
return true;
|
int fd = open(input, O_RDONLY);
|
||||||
|
const uint8_t magic[6] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 };
|
||||||
|
char buf[6] = { 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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user