summaryrefslogtreecommitdiffstats
path: root/lib/dpkg/version.h
blob: cbc76077b89f73bc2ae3e0d47b52c627f90265eb (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * libdpkg - Debian packaging suite library routines
 * version.h - version handling routines
 *
 * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
 * Copyright © 2011-2014 Guillem Jover <guillem@debian.org>
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LIBDPKG_VERSION_H
#define LIBDPKG_VERSION_H

#include <stdbool.h>

#include <dpkg/macros.h>

DPKG_BEGIN_DECLS

/**
 * @defgroup version Version handling
 * @ingroup dpkg-public
 * @{
 */

/**
 * Data structure representing a Debian version.
 *
 * @see deb-version(5)
 */
struct dpkg_version {
	/** The epoch. It will be zero if no epoch is present. */
	unsigned int epoch;
	/** The upstream part of the version. */
	const char *version;
	/** The Debian revision part of the version. */
	const char *revision;
};

/**
 * Compound literal for a dpkg_version.
 */
#define DPKG_VERSION_OBJECT(e, v, r) \
	(struct dpkg_version){ .epoch = (e), .version = (v), .revision = (r) }

#define DPKG_VERSION_INIT \
	DPKG_VERSION_OBJECT(0, NULL, NULL)

/**
 * Enum constants for the supported relation operations that can be done
 * on Debian versions.
 */
enum dpkg_relation {
	/** The “none” relation, sentinel value. */
	DPKG_RELATION_NONE	= 0,
	/** Equality relation (‘=’). */
	DPKG_RELATION_EQ	= DPKG_BIT(0),
	/** Less than relation (‘<<’). */
	DPKG_RELATION_LT	= DPKG_BIT(1),
	/** Less than or equal to relation (‘<=’). */
	DPKG_RELATION_LE	= DPKG_RELATION_LT | DPKG_RELATION_EQ,
	/** Greater than relation (‘>>’). */
	DPKG_RELATION_GT	= DPKG_BIT(2),
	/** Greater than or equal to relation (‘>=’). */
	DPKG_RELATION_GE	= DPKG_RELATION_GT | DPKG_RELATION_EQ,
};

void dpkg_version_blank(struct dpkg_version *version);
bool dpkg_version_is_informative(const struct dpkg_version *version);
int dpkg_version_compare(const struct dpkg_version *a,
                         const struct dpkg_version *b);
bool dpkg_version_relate(const struct dpkg_version *a,
                         enum dpkg_relation rel,
                         const struct dpkg_version *b);

/** @} */

DPKG_END_DECLS

#endif /* LIBDPKG_VERSION_H */