OSDN Git Service

f41add1fdc486f815bd5fb7c833b4d646f361b24
[linuxjm/LDP_man-pages.git] / original / man3 / strverscmp.3
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 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
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 .BR ls (1)
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 .I \-v
44 option to
45 .BR ls (1),
46 which is implemented using
47 .BR versionsort (3),
48 which again uses
49 .BR strverscmp ().
50
51 Thus, the task of
52 .BR strverscmp ()
53 is to compare two strings and find the "right" order, while
54 .BR strcmp (3)
55 only finds the lexicographic order.
56 This function does not use
57 the locale category
58 .BR LC_COLLATE ,
59 so is meant mostly for situations
60 where the strings are expected to be in ASCII.
61
62 What this function does is the following.
63 If both strings are equal, return 0.
64 Otherwise find the position
65 between two bytes with the property that before it both strings are equal,
66 while directly after it there is a difference.
67 Find the largest consecutive digit strings containing (or starting at,
68 or ending at) this position.
69 If one or both of these is empty,
70 then return what
71 .BR strcmp (3)
72 would have returned (numerical ordering of byte values).
73 Otherwise, compare both digit strings numerically, where digit strings with
74 one or more leading zeros are interpreted as if they have a decimal point
75 in front (so that in particular digit strings with more leading zeros
76 come before digit strings with fewer leading zeros).
77 Thus, the ordering is
78 .IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 .
79 .SH "RETURN VALUE"
80 The
81 .BR strverscmp ()
82 function returns an integer
83 less than, equal to, or greater than zero if \fIs1\fP
84 is found, respectively, to be earlier than, equal to,
85 or later than \fIs2\fP.
86 .SH "CONFORMING TO"
87 This function is a GNU extension.
88 .SH "SEE ALSO"
89 .BR rename (1),
90 .BR strcasecmp (3),
91 .BR strcmp (3),
92 .BR strcoll (3)