]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl> |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da | 24 | .\" |
fe0fefbf | 25 | .TH STRVERSCMP 3 2015-03-02 "GNU" "Linux Programmer's Manual" |
fea681da MK |
26 | .SH NAME |
27 | strverscmp \- compare two version strings | |
28 | .SH SYNOPSIS | |
29 | .nf | |
b80f966b | 30 | .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
fea681da MK |
31 | .br |
32 | .B #include <string.h> | |
33 | .sp | |
34 | .BI "int strverscmp(const char *" s1 ", const char *" s2 ); | |
35 | .fi | |
36 | .SH DESCRIPTION | |
37 | Often one has files | |
38 | .IR jan1 ", " jan2 ", ..., " jan9 ", " jan10 ", ..." | |
39 | and it feels wrong when | |
f19a0f03 | 40 | .BR ls (1) |
fea681da | 41 | orders them |
c10859eb | 42 | .IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 . |
fea681da MK |
43 | .\" classical solution: "rename jan jan0 jan?" |
44 | In order to rectify this, GNU introduced the | |
f19a0f03 | 45 | .I \-v |
fea681da MK |
46 | option to |
47 | .BR ls (1), | |
48 | which is implemented using | |
49 | .BR versionsort (3), | |
50 | which again uses | |
e511ffb6 | 51 | .BR strverscmp (). |
fea681da MK |
52 | |
53 | Thus, the task of | |
e511ffb6 | 54 | .BR strverscmp () |
fea681da | 55 | is to compare two strings and find the "right" order, while |
fb186734 | 56 | .BR strcmp (3) |
33a0ccb2 | 57 | finds only the lexicographic order. |
c13182ef | 58 | This function does not use |
097585ed MK |
59 | the locale category |
60 | .BR LC_COLLATE , | |
61 | so is meant mostly for situations | |
fea681da MK |
62 | where the strings are expected to be in ASCII. |
63 | ||
64 | What this function does is the following. | |
c13182ef | 65 | If both strings are equal, return 0. |
2b9b829d | 66 | Otherwise, find the position |
fea681da MK |
67 | between two bytes with the property that before it both strings are equal, |
68 | while directly after it there is a difference. | |
69 | Find the largest consecutive digit strings containing (or starting at, | |
c13182ef MK |
70 | or ending at) this position. |
71 | If one or both of these is empty, | |
fea681da | 72 | then return what |
fb186734 | 73 | .BR strcmp (3) |
fea681da MK |
74 | would have returned (numerical ordering of byte values). |
75 | Otherwise, compare both digit strings numerically, where digit strings with | |
7b01461a MK |
76 | one or more leading zeros are interpreted as if they have a decimal point |
77 | in front (so that in particular digit strings with more leading zeros | |
78 | come before digit strings with fewer leading zeros). | |
fea681da MK |
79 | Thus, the ordering is |
80 | .IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 . | |
47297adb | 81 | .SH RETURN VALUE |
60a90ecd MK |
82 | The |
83 | .BR strverscmp () | |
84 | function returns an integer | |
c6fa0841 MK |
85 | less than, equal to, or greater than zero if |
86 | .I s1 | |
fea681da | 87 | is found, respectively, to be earlier than, equal to, |
c6fa0841 MK |
88 | or later than |
89 | .IR s2 . | |
9aa3ae0b PH |
90 | .SH ATTRIBUTES |
91 | For an explanation of the terms used in this section, see | |
92 | .BR attributes (7). | |
93 | .TS | |
94 | allbox; | |
95 | lb lb lb | |
96 | l l l. | |
97 | Interface Attribute Value | |
98 | T{ | |
99 | .BR strverscmp () | |
72ab1faa MS |
100 | .\" FIXME: the following marking is different from which in glibc manual. |
101 | .\" strverscmp: MT-Safe locale | |
102 | .\" glibc manual says strverscmp should have marking locale because it calls | |
103 | .\" isdigit() multiple times and isdigit() uses locale variable. | |
104 | .\" But isdigit() has two implementations. With different compiling conditions, | |
105 | .\" we may call isdigit() in macro, then strverscmp() should not have locale | |
106 | .\" problem. | |
9aa3ae0b PH |
107 | T} Thread safety MT-Safe |
108 | .TE | |
47297adb | 109 | .SH CONFORMING TO |
fea681da | 110 | This function is a GNU extension. |
47297adb | 111 | .SH SEE ALSO |
fea681da MK |
112 | .BR rename (1), |
113 | .BR strcasecmp (3), | |
114 | .BR strcmp (3), | |
0a4f8b7b | 115 | .BR strcoll (3) |