summaryrefslogtreecommitdiff
path: root/lib/comp/compressor.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-23 02:14:52 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-23 02:37:08 +0200
commit0b22d6ad0ebed2af239259dbfa36cd9920c6f4a2 (patch)
tree0680c237006ed11fc200e9d3d4717d25455e9599 /lib/comp/compressor.c
parent5f7a1a092495c84c4c4cd208c3c983c3f16c8951 (diff)
Move all handling of compressor names to libcompress.a
This commit removes handling of compressor names from gensquashfs. Instead, functions are added to libcompress to obtain name from ID, ID from name and to print out defaults. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/comp/compressor.c')
-rw-r--r--lib/comp/compressor.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/comp/compressor.c b/lib/comp/compressor.c
index 6dff416..506df46 100644
--- a/lib/comp/compressor.c
+++ b/lib/comp/compressor.c
@@ -47,6 +47,15 @@ static const compressor_help_fun_t helpfuns[SQFS_COMP_MAX + 1] = {
#endif
};
+static const char *names[] = {
+ [SQFS_COMP_GZIP] = "gzip",
+ [SQFS_COMP_LZMA] = "lzma",
+ [SQFS_COMP_LZO] = "lzo",
+ [SQFS_COMP_XZ] = "xz",
+ [SQFS_COMP_LZ4] = "lz4",
+ [SQFS_COMP_ZSTD] = "zstd",
+};
+
int generic_write_options(int fd, const void *data, size_t size)
{
uint8_t buffer[size + 2];
@@ -129,6 +138,42 @@ void compressor_print_help(E_SQFS_COMPRESSOR id)
helpfuns[id]();
}
+void compressor_print_available(void)
+{
+ size_t i;
+
+ fputs("Available compressors:\n", stdout);
+
+ for (i = 0; i < sizeof(names) / sizeof(names[0]); ++i) {
+ if (compressor_exists(i))
+ printf("\t%s\n", names[i]);
+ }
+
+ printf("\nDefault compressor: %s\n", names[compressor_get_default()]);
+}
+
+const char *compressor_name_from_id(E_SQFS_COMPRESSOR id)
+{
+ if (id < 0 || (size_t)id > sizeof(names) / sizeof(names[0]))
+ return NULL;
+
+ return names[id];
+}
+
+int compressor_id_from_name(const char *name, E_SQFS_COMPRESSOR *out)
+{
+ size_t i;
+
+ for (i = 0; i < sizeof(names) / sizeof(names[0]); ++i) {
+ if (names[i] != NULL && strcmp(names[i], name) == 0) {
+ *out = i;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
E_SQFS_COMPRESSOR compressor_get_default(void)
{
#if defined(WITH_XZ)