]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strverscmp.3
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[thirdparty/man-pages.git] / man3 / strverscmp.3
CommitLineData
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
25strverscmp \- 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
35Often one has files
36.IR jan1 ", " jan2 ", ..., " jan9 ", " jan10 ", ..."
37and it feels wrong when
38.B ls
39orders them
c10859eb 40.IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 .
fea681da
MK
41.\" classical solution: "rename jan jan0 jan?"
42In order to rectify this, GNU introduced the
43.B \-v
44option to
45.BR ls (1),
46which is implemented using
47.BR versionsort (3),
48which again uses
e511ffb6 49.BR strverscmp ().
fea681da
MK
50
51Thus, the task of
e511ffb6 52.BR strverscmp ()
fea681da 53is to compare two strings and find the "right" order, while
e1d6264d 54.BR strcmp ()
c13182ef
MK
55only finds the lexicographic order.
56This function does not use
fea681da
MK
57the locale category LC_COLLATE, so is meant mostly for situations
58where the strings are expected to be in ASCII.
59
60What this function does is the following.
c13182ef
MK
61If both strings are equal, return 0.
62Otherwise find the position
fea681da
MK
63between two bytes with the property that before it both strings are equal,
64while directly after it there is a difference.
65Find the largest consecutive digit strings containing (or starting at,
c13182ef
MK
66or ending at) this position.
67If one or both of these is empty,
fea681da 68then return what
e1d6264d 69.BR strcmp ()
fea681da
MK
70would have returned (numerical ordering of byte values).
71Otherwise, compare both digit strings numerically, where digit strings with
72one or more leading zeroes are interpreted as if they have a decimal point
73in front (so that in particular digit strings with more leading zeroes
74come before digit strings with fewer leading zeroes).
75Thus, the ordering is
76.IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 .
77.SH "RETURN VALUE"
c13182ef 78The \fBstrverscmp\fP() function returns an integer
fea681da
MK
79less than, equal to, or greater than zero if \fIs1\fP
80is found, respectively, to be earlier than, equal to,
81or later than \fIs2\fP.
82.SH "CONFORMING TO"
83This 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)