1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH STRVERSCMP 3 2001-12-19 "GNU" "Linux Programmer's Manual"
25 strverscmp \- compare two version strings
28 .B #define _GNU_SOURCE
30 .B #include <string.h>
32 .BI "int strverscmp(const char *" s1 ", const char *" s2 );
36 .IR jan1 ", " jan2 ", ..., " jan9 ", " jan10 ", ..."
37 and it feels wrong when
40 .IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 .
41 .\" classical solution: "rename jan jan0 jan?"
42 In order to rectify this, GNU introduced the
46 which is implemented using
53 is to compare two strings and find the "right" order, while
55 only finds the lexicographic order. This function does not use
56 the locale category LC_COLLATE, so is meant mostly for situations
57 where the strings are expected to be in ASCII.
59 What this function does is the following.
60 If both strings are equal, return 0. Otherwise find the position
61 between two bytes with the property that before it both strings are equal,
62 while directly after it there is a difference.
63 Find the largest consecutive digit strings containing (or starting at,
64 or ending at) this position. If one or both of these is empty,
67 would have returned (numerical ordering of byte values).
68 Otherwise, compare both digit strings numerically, where digit strings with
69 one or more leading zeroes are interpreted as if they have a decimal point
70 in front (so that in particular digit strings with more leading zeroes
71 come before digit strings with fewer leading zeroes).
73 .IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 .
75 The \fBstrverscmp\fP() function returns an integer
76 less than, equal to, or greater than zero if \fIs1\fP
77 is found, respectively, to be earlier than, equal to,
78 or later than \fIs2\fP.
80 This function is a GNU extension.