aboutsummaryrefslogtreecommitdiff
path: root/lib/fstream/compressor.c
blob: b8f9c6be4c03a71746429eaa3590d44bb58dad86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * compressor.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#include "internal.h"

int fstream_compressor_id_from_name(const char *name)
{
	if (strcmp(name, "gzip") == 0)
		return FSTREAM_COMPRESSOR_GZIP;

	if (strcmp(name, "xz") == 0)
		return FSTREAM_COMPRESSOR_XZ;

	return -1;
}

const char *fstream_compressor_name_from_id(int id)
{
	if (id == FSTREAM_COMPRESSOR_GZIP)
		return "gzip";

	if (id == FSTREAM_COMPRESSOR_XZ)
		return "xz";

	return NULL;
}

bool fstream_compressor_exists(int id)
{
	switch (id) {
#ifdef WITH_GZIP
	case FSTREAM_COMPRESSOR_GZIP:
		return true;
#endif
#ifdef WITH_XZ
	case FSTREAM_COMPRESSOR_XZ:
		return true;
#endif
	default:
		break;
	}

	return false;
}