From 85e36aab1258d8d9ec7b61ce013f167ef8e03ae0 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 5 Mar 2020 22:38:15 +0100 Subject: Change the signature of sqfs_compressor_create to return an error code Make sure the function has a way of telling the caller *why* it failed. This way, the function can convey whether it had an internal error, an allocation failure, whether the arguments are totaly nonsensical, or simply that the compressor *or specific configuration* is not supported. Signed-off-by: David Oberhollenzer --- lib/sqfs/comp/gzip.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/sqfs/comp/gzip.c') diff --git a/lib/sqfs/comp/gzip.c b/lib/sqfs/comp/gzip.c index 351d733..d702da1 100644 --- a/lib/sqfs/comp/gzip.c +++ b/lib/sqfs/comp/gzip.c @@ -247,7 +247,8 @@ static sqfs_object_t *gzip_create_copy(const sqfs_object_t *cmp) return (sqfs_object_t *)gzip; } -sqfs_compressor_t *gzip_compressor_create(const sqfs_compressor_config_t *cfg) +int gzip_compressor_create(const sqfs_compressor_config_t *cfg, + sqfs_compressor_t **out) { gzip_compressor_t *gzip; sqfs_compressor_t *base; @@ -255,24 +256,24 @@ sqfs_compressor_t *gzip_compressor_create(const sqfs_compressor_config_t *cfg) if (cfg->flags & ~(SQFS_COMP_FLAG_GZIP_ALL | SQFS_COMP_FLAG_GENERIC_ALL)) { - return NULL; + return SQFS_ERROR_UNSUPPORTED; } if (cfg->opt.gzip.level < SQFS_GZIP_MIN_LEVEL || cfg->opt.gzip.level > SQFS_GZIP_MAX_LEVEL) { - return NULL; + return SQFS_ERROR_UNSUPPORTED; } if (cfg->opt.gzip.window_size < SQFS_GZIP_MIN_WINDOW || cfg->opt.gzip.window_size > SQFS_GZIP_MAX_WINDOW) { - return NULL; + return SQFS_ERROR_UNSUPPORTED; } gzip = calloc(1, sizeof(*gzip)); base = (sqfs_compressor_t *)gzip; if (gzip == NULL) - return NULL; + return SQFS_ERROR_ALLOC; gzip->opt.level = cfg->opt.gzip.level; gzip->opt.window = cfg->opt.gzip.window_size; @@ -296,8 +297,9 @@ sqfs_compressor_t *gzip_compressor_create(const sqfs_compressor_config_t *cfg) if (ret != Z_OK) { free(gzip); - return NULL; + return SQFS_ERROR_COMPRESSOR; } - return base; + *out = base; + return 0; } -- cgit v1.2.3