mirror of
https://github.com/pygos/pkg-utils.git
synced 2024-11-24 21:40:43 +01:00
40 lines
751 B
C
40 lines
751 B
C
|
/* SPDX-License-Identifier: ISC */
|
||
|
#include <string.h>
|
||
|
|
||
|
#include "internal.h"
|
||
|
|
||
|
static compressor_t *compressors[] = {
|
||
|
[PKG_COMPRESSION_NONE] = &comp_none,
|
||
|
#ifdef WITH_ZLIB
|
||
|
[PKG_COMPRESSION_ZLIB] = &comp_zlib,
|
||
|
#endif
|
||
|
#ifdef WITH_LZMA
|
||
|
[PKG_COMPRESSION_LZMA] = &comp_lzma,
|
||
|
#endif
|
||
|
};
|
||
|
|
||
|
compressor_t *compressor_by_name(const char *name)
|
||
|
{
|
||
|
size_t i;
|
||
|
|
||
|
for (i = 0; i < sizeof(compressors) / sizeof(compressors[0]); ++i) {
|
||
|
if (compressors[i] == NULL)
|
||
|
continue;
|
||
|
if (strcmp(compressors[i]->name, name) == 0)
|
||
|
return compressors[i];
|
||
|
}
|
||
|
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
compressor_t *compressor_by_id(PKG_COMPRESSION id)
|
||
|
{
|
||
|
if ((int)id < 0)
|
||
|
return NULL;
|
||
|
|
||
|
if ((size_t)id >= sizeof(compressors) / sizeof(compressors[0]))
|
||
|
return NULL;
|
||
|
|
||
|
return compressors[id];
|
||
|
}
|