]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strverscmp.3
Import of man-pages 1.70
[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.
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
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
40.IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 ".
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
49.BR strverscmp .
50
51Thus, the task of
52.B strverscmp
53is to compare two strings and find the "right" order, while
54.B strcmp
55only finds the lexicographic order. This function does not use
56the locale category LC_COLLATE, so is meant mostly for situations
57where the strings are expected to be in ASCII.
58
59What this function does is the following.
60If both strings are equal, return 0. Otherwise find the position
61between two bytes with the property that before it both strings are equal,
62while directly after it there is a difference.
63Find the largest consecutive digit strings containing (or starting at,
64or ending at) this position. If one or both of these is empty,
65then return what
66.B strcmp
67would have returned (numerical ordering of byte values).
68Otherwise, compare both digit strings numerically, where digit strings with
69one or more leading zeroes are interpreted as if they have a decimal point
70in front (so that in particular digit strings with more leading zeroes
71come before digit strings with fewer leading zeroes).
72Thus, the ordering is
73.IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 .
74.SH "RETURN VALUE"
75The \fBstrverscmp()\fP function returns an integer
76less than, equal to, or greater than zero if \fIs1\fP
77is found, respectively, to be earlier than, equal to,
78or later than \fIs2\fP.
79.SH "CONFORMING TO"
80This 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)