221 lines
5.9 KiB
HTML
221 lines
5.9 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of STRVERSCMP</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>STRVERSCMP</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
strverscmp - compare two version strings
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#define _GNU_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
|
|
<B>#include <<A HREF="file:///usr/include/string.h">string.h</A>></B>
|
|
|
|
<B>int strverscmp(const char *</B><I>s1</I><B>, const char *</B><I>s2</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
Often one has files
|
|
<I>jan1</I>, <I>jan2</I>, ..., <I>jan9</I>, <I>jan10</I>, ...
|
|
|
|
and it feels wrong when
|
|
<B><A HREF="/cgi-bin/man/man2html?1+ls">ls</A></B>(1)
|
|
|
|
orders them
|
|
<I>jan1</I>, <I>jan10</I>, ..., <I>jan2</I>, ..., <I>jan9</I>.
|
|
|
|
|
|
In order to rectify this, GNU introduced the
|
|
<I>-v</I>
|
|
|
|
option to
|
|
<B><A HREF="/cgi-bin/man/man2html?1+ls">ls</A></B>(1),
|
|
|
|
which is implemented using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+versionsort">versionsort</A></B>(3),
|
|
|
|
which again uses
|
|
<B>strverscmp</B>().
|
|
|
|
<P>
|
|
|
|
Thus, the task of
|
|
<B>strverscmp</B>()
|
|
|
|
is to compare two strings and find the "right" order, while
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strcmp">strcmp</A></B>(3)
|
|
|
|
finds only the lexicographic order.
|
|
This function does not use
|
|
the locale category
|
|
<B>LC_COLLATE</B>,
|
|
|
|
so is meant mostly for situations
|
|
where the strings are expected to be in ASCII.
|
|
<P>
|
|
|
|
What this function does is the following.
|
|
If both strings are equal, return 0.
|
|
Otherwise, find the position
|
|
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,
|
|
or ending at) this position.
|
|
If one or both of these is empty,
|
|
then return what
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strcmp">strcmp</A></B>(3)
|
|
|
|
would have returned (numerical ordering of byte values).
|
|
Otherwise, compare both digit strings numerically, where digit strings with
|
|
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).
|
|
Thus, the ordering is
|
|
<I>000</I>, <I>00</I>, <I>01</I>, <I>010</I>, <I>09</I>, <I>0</I>, <I>1</I>, <I>9</I>, <I>10</I>.
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The
|
|
<B>strverscmp</B>()
|
|
|
|
function returns an integer
|
|
less than, equal to, or greater than zero if
|
|
<I>s1</I>
|
|
|
|
is found, respectively, to be earlier than, equal to,
|
|
or later than
|
|
<I>s2</I>.
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>strverscmp</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
This function is a GNU extension.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The program below can be used to demonstrate the behavior of
|
|
<B>strverscmp</B>().
|
|
|
|
It uses
|
|
<B>strverscmp</B>()
|
|
|
|
to compare the two strings given as its command-line arguments.
|
|
An example of its use is the following:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>./a.out jan1 jan10</B>
|
|
jan1 < jan10
|
|
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Program source</H3>
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
#include <<A HREF="file:///usr/include/string.h">string.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> int res;
|
|
<P>
|
|
<BR> if (argc != 3) {
|
|
<BR> fprintf(stderr, "Usage: %s <string1> <string2>\n", argv[0]);
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> res = strverscmp(argv[1], argv[2]);
|
|
<P>
|
|
<BR> printf("%s %s %s\n", argv[1],
|
|
<BR> (res < 0) ? "<" : (res == 0) ? "==" : ">", argv[2]);
|
|
<P>
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+rename">rename</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strcasecmp">strcasecmp</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strcmp">strcmp</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strcoll">strcoll</A></B>(3)
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">ATTRIBUTES</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="8"><A HREF="#lbAI">Program source</A><DD>
|
|
</DL>
|
|
<DT id="9"><A HREF="#lbAJ">SEE ALSO</A><DD>
|
|
<DT id="10"><A HREF="#lbAK">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:58 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|