1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | #ifndef PERF_COMPRESS_H |
3 | #define PERF_COMPRESS_H |
4 | |
5 | #include <stdbool.h> |
6 | #include <stddef.h> |
7 | #include <sys/types.h> |
8 | #ifdef HAVE_ZSTD_SUPPORT |
9 | #include <zstd.h> |
10 | #endif |
11 | |
12 | #ifdef HAVE_ZLIB_SUPPORT |
13 | int gzip_decompress_to_file(const char *input, int output_fd); |
14 | bool gzip_is_compressed(const char *input); |
15 | #endif |
16 | |
17 | #ifdef HAVE_LZMA_SUPPORT |
18 | int lzma_decompress_to_file(const char *input, int output_fd); |
19 | bool lzma_is_compressed(const char *input); |
20 | #endif |
21 | |
22 | struct zstd_data { |
23 | #ifdef HAVE_ZSTD_SUPPORT |
24 | ZSTD_CStream *cstream; |
25 | ZSTD_DStream *dstream; |
26 | int comp_level; |
27 | #endif |
28 | }; |
29 | |
30 | #ifdef HAVE_ZSTD_SUPPORT |
31 | |
32 | int zstd_init(struct zstd_data *data, int level); |
33 | int zstd_fini(struct zstd_data *data); |
34 | |
35 | ssize_t zstd_compress_stream_to_records(struct zstd_data *data, void *dst, size_t dst_size, |
36 | void *src, size_t src_size, size_t max_record_size, |
37 | size_t process_header(void *record, size_t increment)); |
38 | |
39 | size_t zstd_decompress_stream(struct zstd_data *data, void *src, size_t src_size, |
40 | void *dst, size_t dst_size); |
41 | #else /* !HAVE_ZSTD_SUPPORT */ |
42 | |
43 | static inline int zstd_init(struct zstd_data *data __maybe_unused, int level __maybe_unused) |
44 | { |
45 | return 0; |
46 | } |
47 | |
48 | static inline int zstd_fini(struct zstd_data *data __maybe_unused) |
49 | { |
50 | return 0; |
51 | } |
52 | |
53 | static inline |
54 | ssize_t zstd_compress_stream_to_records(struct zstd_data *data __maybe_unused, |
55 | void *dst __maybe_unused, size_t dst_size __maybe_unused, |
56 | void *src __maybe_unused, size_t src_size __maybe_unused, |
57 | size_t max_record_size __maybe_unused, |
58 | size_t (void *record, size_t increment) __maybe_unused) |
59 | { |
60 | return 0; |
61 | } |
62 | |
63 | static inline size_t zstd_decompress_stream(struct zstd_data *data __maybe_unused, void *src __maybe_unused, |
64 | size_t src_size __maybe_unused, void *dst __maybe_unused, |
65 | size_t dst_size __maybe_unused) |
66 | { |
67 | return 0; |
68 | } |
69 | #endif |
70 | |
71 | #endif /* PERF_COMPRESS_H */ |
72 | |