compress: introduce compression_supported() helper function

This commit is contained in:
Yu Watanabe
2023-04-04 14:34:32 +09:00
parent 9dfbae203e
commit 83f3d73da8
2 changed files with 13 additions and 0 deletions

View File

@@ -65,6 +65,16 @@ static const char* const compression_table[_COMPRESSION_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(compression, Compression);
bool compression_supported(Compression c) {
static const unsigned supported =
(1U << COMPRESSION_NONE) |
(1U << COMPRESSION_XZ) * HAVE_XZ |
(1U << COMPRESSION_LZ4) * HAVE_LZ4 |
(1U << COMPRESSION_ZSTD) * HAVE_ZSTD;
return c >= 0 && c < _COMPRESSION_MAX && FLAGS_SET(supported, 1U << c);
}
int compress_blob_xz(const void *src, uint64_t src_size,
void *dst, size_t dst_alloc_size, size_t *dst_size) {
#if HAVE_XZ

View File

@@ -2,6 +2,7 @@
#pragma once
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
@@ -17,6 +18,8 @@ typedef enum Compression {
const char* compression_to_string(Compression compression);
Compression compression_from_string(const char *compression);
bool compression_supported(Compression c);
int compress_blob_xz(const void *src, uint64_t src_size,
void *dst, size_t dst_alloc_size, size_t *dst_size);
int compress_blob_lz4(const void *src, uint64_t src_size,