Skip to content

Commit

Permalink
extractor.c: make extractor_by_id usable by other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Gottox committed Jul 31, 2023
1 parent a93c241 commit 8f3aa41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions include/sqsh_extract_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ struct SqshExtractor {
size_t block_size;
};

/**
* @internal
* @memberof SqshExtractor
* @brief Returns the extractor implementation for a given id.
*
* @param[in] id The id of the compression algorithm to use.
*
* @return pointer to the extractor implementation or NULL if the extraction
* algorithm is not supported.
*/
const struct SqshExtractorImpl *sqsh__extractor_impl_from_id(int id);

/**
* @internal
* @memberof SqshExtractor
Expand Down
5 changes: 5 additions & 0 deletions lib/extract/extract_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ sqsh__extract_manager_init(
SQSH_CONFIG_DEFAULT(config->compression_lru_size, 128);
const struct SqshSuperblock *superblock = sqsh_archive_superblock(archive);

if (sqsh__extractor_impl_from_id(sqsh_superblock_compression_id(superblock)) ==
NULL) {
return -SQSH_ERROR_COMPRESSION_UNSUPPORTED;
}

if (size == 0) {
return -SQSH_ERROR_SIZE_MISMATCH;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/extract/extractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const struct SqshExtractorImpl *const __attribute__((weak)) sqsh__impl_lzo =
NULL;

const struct SqshExtractorImpl *
extractor_by_id(int id) {
sqsh__extractor_impl_from_id(int id) {
switch ((enum SqshSuperblockCompressionId)id) {
case SQSH_COMPRESSION_GZIP:
return sqsh__impl_zlib;
Expand All @@ -64,7 +64,7 @@ int
sqsh__extractor_init(
struct SqshExtractor *extractor, struct SqshBuffer *buffer,
int algorithm_id, size_t block_size) {
const struct SqshExtractorImpl *impl = extractor_by_id(algorithm_id);
const struct SqshExtractorImpl *impl = sqsh__extractor_impl_from_id(algorithm_id);
if (impl == NULL) {
return -SQSH_ERROR_COMPRESSION_UNSUPPORTED;
}
Expand Down

0 comments on commit 8f3aa41

Please sign in to comment.