1STRVERSCMP(3)              Linux Programmer's Manual             STRVERSCMP(3)
2
3
4

NAME

6       strverscmp - compare two version strings
7

SYNOPSIS

9       #define _GNU_SOURCE
10       #include <string.h>
11
12       int strverscmp(const char *s1, const char *s2);
13

DESCRIPTION

15       Often  one  has  files  jan1, jan2, ..., jan9, jan10, ...  and it feels
16       wrong when ls orders them jan1, jan10, ..., jan2, ..., jan9.  In  order
17       to rectify this, GNU introduced the -v option to ls(1), which is imple‐
18       mented using versionsort(3), which again uses strverscmp().
19
20       Thus, the task of strverscmp() is to compare two strings and  find  the
21       "right"  order, while strcmp() only finds the lexicographic order. This
22       function does not use the  locale  category  LC_COLLATE,  so  is  meant
23       mostly for situations where the strings are expected to be in ASCII.
24
25       What  this  function does is the following.  If both strings are equal,
26       return 0. Otherwise find the position between two bytes with the  prop‐
27       erty  that  before  it  both strings are equal, while directly after it
28       there is a difference.  Find the largest consecutive digit strings con‐
29       taining (or starting at, or ending at) this position. If one or both of
30       these is empty, then return what strcmp() would have returned  (numeri‐
31       cal  ordering  of  byte values).  Otherwise, compare both digit strings
32       numerically, where digit strings with one or more  leading  zeroes  are
33       interpreted  as  if they have a decimal point in front (so that in par‐
34       ticular digit strings  with  more  leading  zeroes  come  before  digit
35       strings with fewer leading zeroes).  Thus, the ordering is 000, 00, 01,
36       010, 09, 0, 1, 9, 10.
37

RETURN VALUE

39       The strverscmp() function returns an integer less than,  equal  to,  or
40       greater  than  zero  if  s1 is found, respectively, to be earlier than,
41       equal to, or later than s2.
42

CONFORMING TO

44       This function is a GNU extension.
45

SEE ALSO

47       rename(1), strcasecmp(3), strcmp(3), strcoll(3), feature_test_macros(7)
48
49
50
51GNU                               2001-12-19                     STRVERSCMP(3)
Impressum