diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-05 22:55:09 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-05 22:55:09 +0100 |
commit | dfab234dfae735103d2e5206b0f335c8449ee3d5 (patch) | |
tree | 1b5d79f6a5f5a01896562233ee40973085755c21 /lib/common/compress.c | |
parent | 85e36aab1258d8d9ec7b61ce013f167ef8e03ae0 (diff) |
Get rid of sqfs_compressor_exists
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common/compress.c')
-rw-r--r-- | lib/common/compress.c | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/lib/common/compress.c b/lib/common/compress.c index 3ee242d..cb4ce10 100644 --- a/lib/common/compress.c +++ b/lib/common/compress.c @@ -6,31 +6,64 @@ */ #include "common.h" +static int cmp_ids[] = { + SQFS_COMP_XZ, + SQFS_COMP_ZSTD, + SQFS_COMP_GZIP, + SQFS_COMP_LZ4, + SQFS_COMP_LZO, +}; + SQFS_COMPRESSOR compressor_get_default(void) { - if (sqfs_compressor_exists(SQFS_COMP_XZ)) - return SQFS_COMP_XZ; + sqfs_compressor_config_t cfg; + sqfs_compressor_t *temp; + size_t i; + int ret; + + for (i = 0; i < sizeof(cmp_ids) / sizeof(cmp_ids[0]); ++i) { + sqfs_compressor_config_init(&cfg, cmp_ids[i], + SQFS_DEFAULT_BLOCK_SIZE, 0); - if (sqfs_compressor_exists(SQFS_COMP_ZSTD)) - return SQFS_COMP_ZSTD; + ret = sqfs_compressor_create(&cfg, &temp); - return SQFS_COMP_GZIP; + if (ret == 0) { + sqfs_destroy(temp); + return cmp_ids[i]; + } + } + +#ifdef WITH_LZO + return SQFS_COMP_LZO; +#else + assert(0); +#endif } void compressor_print_available(void) { + sqfs_compressor_config_t cfg; + sqfs_compressor_t *temp; bool have_compressor; - int i; + int i, ret; fputs("Available compressors:\n", stdout); for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) { - have_compressor = sqfs_compressor_exists(i); + sqfs_compressor_config_init(&cfg, i, + SQFS_DEFAULT_BLOCK_SIZE, 0); -#ifdef WITH_LZO - if (i == SQFS_COMP_LZO) + ret = sqfs_compressor_create(&cfg, &temp); + + if (ret == 0) { + sqfs_destroy(temp); have_compressor = true; + } else { +#ifdef WITH_LZO + if (i == SQFS_COMP_LZO) + have_compressor = true; #endif + } if (have_compressor) printf("\t%s\n", sqfs_compressor_name_from_id(i)); |