OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / strverscmp.3
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH STRVERSCMP 3  2001-12-19 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 strverscmp \- compare two version strings
28 .SH SYNOPSIS
29 .nf
30 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
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
40 .BR ls (1)
41 orders them
42 .IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 .
43 .\" classical solution: "rename jan jan0 jan?"
44 In order to rectify this, GNU introduced the
45 .I \-v
46 option to
47 .BR ls (1),
48 which is implemented using
49 .BR versionsort (3),
50 which again uses
51 .BR strverscmp ().
52
53 Thus, the task of
54 .BR strverscmp ()
55 is to compare two strings and find the "right" order, while
56 .BR strcmp (3)
57 finds only the lexicographic order.
58 This function does not use
59 the locale category
60 .BR LC_COLLATE ,
61 so is meant mostly for situations
62 where the strings are expected to be in ASCII.
63
64 What this function does is the following.
65 If both strings are equal, return 0.
66 Otherwise, find the position
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,
70 or ending at) this position.
71 If one or both of these is empty,
72 then return what
73 .BR strcmp (3)
74 would have returned (numerical ordering of byte values).
75 Otherwise, compare both digit strings numerically, where digit strings with
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).
79 Thus, the ordering is
80 .IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 .
81 .SH RETURN VALUE
82 The
83 .BR strverscmp ()
84 function returns an integer
85 less than, equal to, or greater than zero if
86 .I s1
87 is found, respectively, to be earlier than, equal to,
88 or later than
89 .IR s2 .
90 .SH CONFORMING TO
91 This function is a GNU extension.
92 .SH SEE ALSO
93 .BR rename (1),
94 .BR strcasecmp (3),
95 .BR strcmp (3),
96 .BR strcoll (3)
97 .SH COLOPHON
98 This page is part of release 3.79 of the Linux
99 .I man-pages
100 project.
101 A description of the project,
102 information about reporting bugs,
103 and the latest version of this page,
104 can be found at
105 \%http://www.kernel.org/doc/man\-pages/.