]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl> |
2 | .\" | |
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. | |
6 | .\" | |
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. | |
c13182ef | 11 | .\" |
fea681da MK |
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 | |
18 | .\" professionally. | |
c13182ef | 19 | .\" |
fea681da MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
23 | .TH STRVERSCMP 3 2001-12-19 "GNU" "Linux Programmer's Manual" | |
24 | .SH NAME | |
25 | strverscmp \- compare two version strings | |
26 | .SH SYNOPSIS | |
27 | .nf | |
28 | .B #define _GNU_SOURCE | |
29 | .br | |
30 | .B #include <string.h> | |
31 | .sp | |
32 | .BI "int strverscmp(const char *" s1 ", const char *" s2 ); | |
33 | .fi | |
34 | .SH DESCRIPTION | |
35 | Often one has files | |
36 | .IR jan1 ", " jan2 ", ..., " jan9 ", " jan10 ", ..." | |
37 | and it feels wrong when | |
38 | .B ls | |
39 | orders them | |
c10859eb | 40 | .IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 . |
fea681da MK |
41 | .\" classical solution: "rename jan jan0 jan?" |
42 | In order to rectify this, GNU introduced the | |
43 | .B \-v | |
44 | option to | |
45 | .BR ls (1), | |
46 | which is implemented using | |
47 | .BR versionsort (3), | |
48 | which again uses | |
e511ffb6 | 49 | .BR strverscmp (). |
fea681da MK |
50 | |
51 | Thus, the task of | |
e511ffb6 | 52 | .BR strverscmp () |
fea681da | 53 | is to compare two strings and find the "right" order, while |
e1d6264d | 54 | .BR strcmp () |
c13182ef MK |
55 | only finds the lexicographic order. |
56 | This function does not use | |
fea681da MK |
57 | the locale category LC_COLLATE, so is meant mostly for situations |
58 | where the strings are expected to be in ASCII. | |
59 | ||
60 | What this function does is the following. | |
c13182ef MK |
61 | If both strings are equal, return 0. |
62 | Otherwise find the position | |
fea681da MK |
63 | between two bytes with the property that before it both strings are equal, |
64 | while directly after it there is a difference. | |
65 | Find the largest consecutive digit strings containing (or starting at, | |
c13182ef MK |
66 | or ending at) this position. |
67 | If one or both of these is empty, | |
fea681da | 68 | then return what |
e1d6264d | 69 | .BR strcmp () |
fea681da MK |
70 | would have returned (numerical ordering of byte values). |
71 | Otherwise, compare both digit strings numerically, where digit strings with | |
72 | one or more leading zeroes are interpreted as if they have a decimal point | |
73 | in front (so that in particular digit strings with more leading zeroes | |
74 | come before digit strings with fewer leading zeroes). | |
75 | Thus, the ordering is | |
76 | .IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 . | |
77 | .SH "RETURN VALUE" | |
c13182ef | 78 | The \fBstrverscmp\fP() function returns an integer |
fea681da MK |
79 | less than, equal to, or greater than zero if \fIs1\fP |
80 | is found, respectively, to be earlier than, equal to, | |
81 | or later than \fIs2\fP. | |
82 | .SH "CONFORMING TO" | |
83 | This function is a GNU extension. | |
84 | .SH "SEE ALSO" | |
85 | .BR rename (1), | |
86 | .BR strcasecmp (3), | |
87 | .BR strcmp (3), | |
0a90178c MK |
88 | .BR strcoll (3), |
89 | .BR feature_test_macros (7) |