2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.TH STRVERSCMP 3 2001-12-19 "GNU" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
|
|
|
strverscmp \- compare two version strings
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
getresuid.2, mremap.2, poll.2, remap_file_pages.2, setresuid.2, splice.2, sync_file_range.2, syscall.2, tee.2, vmsplice.2, INFINITY.3, aio_init.3, asprintf.3, assert_perror.3, basename.3, bsd_signal.3, canonicalize_file_name.3, clog10.3, crypt.3, dl_iterate_phdr.3, dlopen.3, encrypt.3, exp10.3, fcloseall.3, fenv.3, fopencookie.3, ftw.3, getaddrinfo_a.3, getloadavg.3, getutent.3, grantpt.3, hsearch.3, lseek64.3, memmem.3, mempcpy.3, pow10.3, program_invocation_name.3, ptsname.3, putgrent.3, sched_getcpu.3, sincos.3, strchr.3, strfry.3, strnlen.3, strptime.3, strstr.3, strverscmp.3, swab.3, sysv_signal.3, tsearch.3, unlockpt.3, wcwidth.3: Add reference to feature_test_macros(7)
Some pages simply list feature test macro requirements in
the form:
#define #GNU_SOURCE
#include <someheader.h>
For these pages, add a "See feature_test_macros(7)" comment
on the "#define" line.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-31 04:31:47 +00:00
|
|
|
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
|
2004-11-03 13:51:07 +00:00
|
|
|
.br
|
|
|
|
.B #include <string.h>
|
|
|
|
.sp
|
|
|
|
.BI "int strverscmp(const char *" s1 ", const char *" s2 );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
Often one has files
|
|
|
|
.IR jan1 ", " jan2 ", ..., " jan9 ", " jan10 ", ..."
|
|
|
|
and it feels wrong when
|
2007-06-23 07:56:56 +00:00
|
|
|
.BR ls (1)
|
2004-11-03 13:51:07 +00:00
|
|
|
orders them
|
2006-05-31 22:16:55 +00:00
|
|
|
.IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 .
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" classical solution: "rename jan jan0 jan?"
|
|
|
|
In order to rectify this, GNU introduced the
|
2007-06-23 07:56:56 +00:00
|
|
|
.I \-v
|
2004-11-03 13:51:07 +00:00
|
|
|
option to
|
|
|
|
.BR ls (1),
|
|
|
|
which is implemented using
|
|
|
|
.BR versionsort (3),
|
|
|
|
which again uses
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR strverscmp ().
|
2004-11-03 13:51:07 +00:00
|
|
|
|
|
|
|
Thus, the task of
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR strverscmp ()
|
2004-11-03 13:51:07 +00:00
|
|
|
is to compare two strings and find the "right" order, while
|
2007-05-12 00:30:29 +00:00
|
|
|
.BR strcmp (3)
|
2007-04-12 22:42:49 +00:00
|
|
|
only finds the lexicographic order.
|
|
|
|
This function does not use
|
2007-06-22 20:40:07 +00:00
|
|
|
the locale category
|
|
|
|
.BR LC_COLLATE ,
|
|
|
|
so is meant mostly for situations
|
2004-11-03 13:51:07 +00:00
|
|
|
where the strings are expected to be in ASCII.
|
|
|
|
|
|
|
|
What this function does is the following.
|
2007-04-12 22:42:49 +00:00
|
|
|
If both strings are equal, return 0.
|
|
|
|
Otherwise find the position
|
2004-11-03 13:51:07 +00:00
|
|
|
between two bytes with the property that before it both strings are equal,
|
|
|
|
while directly after it there is a difference.
|
|
|
|
Find the largest consecutive digit strings containing (or starting at,
|
2007-04-12 22:42:49 +00:00
|
|
|
or ending at) this position.
|
|
|
|
If one or both of these is empty,
|
2004-11-03 13:51:07 +00:00
|
|
|
then return what
|
2007-05-12 00:30:29 +00:00
|
|
|
.BR strcmp (3)
|
2004-11-03 13:51:07 +00:00
|
|
|
would have returned (numerical ordering of byte values).
|
|
|
|
Otherwise, compare both digit strings numerically, where digit strings with
|
2008-03-19 09:04:12 +00:00
|
|
|
one or more leading zeros are interpreted as if they have a decimal point
|
|
|
|
in front (so that in particular digit strings with more leading zeros
|
|
|
|
come before digit strings with fewer leading zeros).
|
2004-11-03 13:51:07 +00:00
|
|
|
Thus, the ordering is
|
|
|
|
.IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 .
|
|
|
|
.SH "RETURN VALUE"
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR strverscmp ()
|
|
|
|
function returns an integer
|
2004-11-03 13:51:07 +00:00
|
|
|
less than, equal to, or greater than zero if \fIs1\fP
|
|
|
|
is found, respectively, to be earlier than, equal to,
|
|
|
|
or later than \fIs2\fP.
|
|
|
|
.SH "CONFORMING TO"
|
|
|
|
This function is a GNU extension.
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR rename (1),
|
|
|
|
.BR strcasecmp (3),
|
|
|
|
.BR strcmp (3),
|
getresuid.2, intro.2, mremap.2, open.2, poll.2, posix_fadvise.2, pread.2, remap_file_pages.2, setresuid.2, signal.2, splice.2, sync_file_range.2, tee.2, vmsplice.2, INFINITY.3, asprintf.3, assert_perror.3, basename.3, bsd_signal.3, canonicalize_file_name.3, clog10.3, crypt.3, dl_iterate_phdr.3, dlopen.3, dprintf.3, encrypt.3, exp10.3, fcloseall.3, fenv.3, ffs.3, fmemopen.3, fopencookie.3, ftw.3, getdate.3, getline.3, getloadavg.3, getopt.3, getsubopt.3, getutent.3, grantpt.3, hsearch.3, intro.3, lseek64.3, memmem.3, mempcpy.3, mq_receive.3, mq_send.3, posix_fallocate.3, pow10.3, program_invocation_name.3, ptsname.3, putgrent.3, readdir.3, sigset.3, sincos.3, stpcpy.3, stpncpy.3, strchr.3, strfry.3, strnlen.3, strptime.3, strsignal.3, strstr.3, strverscmp.3, swab.3, sysv_signal.3, tsearch.3, unlocked_stdio.3, unlockpt.3, wcpcpy.3, wcpncpy.3, wcsdup.3, wcwidth.3: SEE ALSO: Remove redundant reference to feature_test_macros(7)
Reported-by: Florian Lehmann <flo.lehmann@googlemail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-31 05:05:22 +00:00
|
|
|
.BR strcoll (3)
|