diff options
| author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-05 22:38:15 +0100 | 
|---|---|---|
| committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-05 22:41:04 +0100 | 
| commit | 85e36aab1258d8d9ec7b61ce013f167ef8e03ae0 (patch) | |
| tree | b1d59cce7894520b53c6b1fa86666d91587aaf82 /lib/sqfs/comp/gzip.c | |
| parent | 5acb22a6a7168f8b961777482f39a125158def50 (diff) | |
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/comp/gzip.c')
| -rw-r--r-- | lib/sqfs/comp/gzip.c | 16 | 
1 files changed, 9 insertions, 7 deletions
| 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;  } | 
