1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-11-06 05:37:10 +01:00
pkg-utils/lib/comp/compressor.c
David Oberhollenzer 1205ca0f3b Move compressors to utility library
- Remove compressor registration interface. Doesn't work in a static
   library, since all the files containing no exported members are
   optimized away at link time.
 - Repack as seperate utility library.

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
2019-04-05 12:22:47 +02:00

39 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];
}