summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sqfs/compressor.h8
-rw-r--r--lib/sqfs/comp/compressor.c8
-rw-r--r--mkfs/options.c18
-rw-r--r--tar/tar2sqfs.c16
4 files changed, 22 insertions, 28 deletions
diff --git a/include/sqfs/compressor.h b/include/sqfs/compressor.h
index 4f22b0d..5e0be5d 100644
--- a/include/sqfs/compressor.h
+++ b/include/sqfs/compressor.h
@@ -384,13 +384,11 @@ SQFS_API const char *sqfs_compressor_name_from_id(E_SQFS_COMPRESSOR id);
* available.
*
* @param name The name of the compressor backend.
- * @param out Returns the coresponding @ref E_SQFS_COMPRESSOR identifier.
*
- * @return Zero on success, @ref SQFS_ERROR_UNSUPPORTED if the backend
- * is unknown.
+ * @return A positive, @ref E_SQFS_COMPRESSOR identifier on success
+ * or @ref SQFS_ERROR_UNSUPPORTED if the backend is unknown.
*/
-SQFS_API
-int sqfs_compressor_id_from_name(const char *name, E_SQFS_COMPRESSOR *out);
+SQFS_API int sqfs_compressor_id_from_name(const char *name);
#ifdef __cplusplus
}
diff --git a/lib/sqfs/comp/compressor.c b/lib/sqfs/comp/compressor.c
index 0b8b5e9..8049ade 100644
--- a/lib/sqfs/comp/compressor.c
+++ b/lib/sqfs/comp/compressor.c
@@ -130,15 +130,13 @@ const char *sqfs_compressor_name_from_id(E_SQFS_COMPRESSOR id)
return names[id];
}
-int sqfs_compressor_id_from_name(const char *name, E_SQFS_COMPRESSOR *out)
+int sqfs_compressor_id_from_name(const char *name)
{
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;
- }
+ if (names[i] != NULL && strcmp(names[i], name) == 0)
+ return i;
}
return SQFS_ERROR_UNSUPPORTED;
diff --git a/mkfs/options.c b/mkfs/options.c
index 31b7731..4dce84e 100644
--- a/mkfs/options.c
+++ b/mkfs/options.c
@@ -146,7 +146,7 @@ const char *help_details =
void process_command_line(options_t *opt, int argc, char **argv)
{
bool have_compressor;
- int i;
+ int i, ret;
memset(opt, 0, sizeof(*opt));
sqfs_writer_cfg_init(&opt->cfg);
@@ -159,25 +159,23 @@ void process_command_line(options_t *opt, int argc, char **argv)
switch (i) {
case 'c':
have_compressor = true;
+ ret = sqfs_compressor_id_from_name(optarg);
- if (sqfs_compressor_id_from_name(optarg,
- &opt->cfg.comp_id)) {
+ if (ret < 0) {
have_compressor = false;
- }
-
- if (!sqfs_compressor_exists(opt->cfg.comp_id))
- have_compressor = false;
-
#ifdef WITH_LZO
- if (opt->cfg.comp_id == SQFS_COMP_LZO)
- have_compressor = true;
+ if (opt->cfg.comp_id == SQFS_COMP_LZO)
+ have_compressor = true;
#endif
+ }
if (!have_compressor) {
fprintf(stderr, "Unsupported compressor '%s'\n",
optarg);
exit(EXIT_FAILURE);
}
+
+ opt->cfg.comp_id = ret;
break;
case 'b':
opt->cfg.block_size = strtol(optarg, NULL, 0);
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index 0076537..56ae5dc 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -97,7 +97,7 @@ static FILE *input_file = NULL;
static void process_args(int argc, char **argv)
{
bool have_compressor;
- int i;
+ int i, ret;
sqfs_writer_cfg_init(&cfg);
@@ -120,23 +120,23 @@ static void process_args(int argc, char **argv)
break;
case 'c':
have_compressor = true;
+ ret = sqfs_compressor_id_from_name(optarg);
- if (sqfs_compressor_id_from_name(optarg, &cfg.comp_id))
+ if (ret < 0) {
have_compressor = false;
-
- if (!sqfs_compressor_exists(cfg.comp_id))
- have_compressor = false;
-
#ifdef WITH_LZO
- if (cfg.comp_id == SQFS_COMP_LZO)
- have_compressor = true;
+ if (cfg.comp_id == SQFS_COMP_LZO)
+ have_compressor = true;
#endif
+ }
if (!have_compressor) {
fprintf(stderr, "Unsupported compressor '%s'\n",
optarg);
exit(EXIT_FAILURE);
}
+
+ cfg.comp_id = ret;
break;
case 'j':
cfg.num_jobs = strtol(optarg, NULL, 0);