utils/versioncmp.h: Add a wrapper macro for `versioncmp'.
[mLib] / utils / versioncmp.3
CommitLineData
0683223a
MW
1.\" -*-nroff-*-
2.TH versioncmp 3 "6 January 2007" "Straylight/Edgeware" "mLib utilities library"
3.SH NAME
4versioncmp \- compare Debian-format version numbers
5.\" @versioncmp
804935b9 6.\" @VERSIONCMP
0683223a
MW
7.SH SYNOPSIS
8.nf
9.B "#include <mLib/versioncmp.h>"
10
11.BI "int versioncmp(const char *" va ", const char *" vb ");"
804935b9 12.BI "int VERSIONCMP(const char *" va ", " op ", const char *" vb ");"
0683223a
MW
13.fi
14.SH DESCRIPTION
15The
16.B versioncmp
17function compares version strings.
18.PP
19The format of version numbers considered is
20.IP
21.RI [ epoch
22.BR : ]
23.I main
24.RB [ \-
25.IR sub ]
26.PP
27The
28.I main
29part may contain colons or hyphens if there is an
30.I epoch
31or
32.IR sub ,
33respectively. Version strings are compared componentwise: first epochs,
34then main parts, and finally subparts.
35.PP
36The component comparison is done as follows. First, the initial
37subsequence of nondigit characters is extracted from each string, and
38these are compared lexicographically, using ASCII ordering, except that
39letters precede non-letters. If both are the same, an initial sequence
40of digits is extracted from the remaining parts of the version strings,
41and these are compared numerically (an empty sequence being considered
42to have the value zero). This process is repeated until we have a
43winner or until both strings are exhausted.
44.PP
d4efbcd9 45The return value is 0 if the two strings are equal, \-1 if
0683223a
MW
46.I va
47is older than
48.IR vb ,
49or +1 if
50.I va
51is newer than
52.IR vb .
804935b9
MW
53.PP
54The
55.B VERSIONCMP
56macro provides a more convenient syntax for the
57.B versioncmp
58function, by allowing a relational operator to be written between the
59operands.
0683223a
MW
60.SH SEE ALSO
61.BR mLib (3).
62.PP
63.IR "Debian Policy Manual" .
64.SH AUTHOR
65Mark Wooding, <mdw@distorted.org.uk>