]>
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. | |
11 | .\" | |
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. | |
19 | .\" | |
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 | |
40 | .IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 ". | |
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 MK |
53 | is to compare two strings and find the "right" order, while |
54 | .B strcmp | |
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. | |
58 | ||
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, | |
65 | then return what | |
66 | .B strcmp | |
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). | |
72 | Thus, the ordering is | |
73 | .IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 . | |
74 | .SH "RETURN VALUE" | |
63aa9df0 | 75 | The \fBstrverscmp\fP() function returns an integer |
fea681da MK |
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. | |
79 | .SH "CONFORMING TO" | |
80 | This function is a GNU extension. | |
81 | .SH "SEE ALSO" | |
82 | .BR rename (1), | |
83 | .BR strcasecmp (3), | |
84 | .BR strcmp (3), | |
85 | .BR strcoll (3) |