1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| | /*
* Based on an implementation by Brad Conroy (technosaurus)
* published on the Puppy Linux forums.
*
* This work is released to the Public Domain.
* In locales that do not recognize public domain it is:
* Copyright Brad Conroy 2012, permission is hereby granted to use this work in
* accordance with any license approved by the Open Source Initiative for any
* purpose without restriction in perpetuity.
*/
#include <string.h>
int strverscmp(const char *l, const char *r)
{
int ret=0, buf=0;
while ( *l && *r && l[0]==r[0] ) {
l++;
r++;
}
do {
ret=(10 * ret) + l++[0] - '0';
} while ( '0' <= l[0] && l[0] <= '9') ;
do {
buf=(10 * buf) + r++[0] - '0';
} while ( '0' <= r[0] && r[0] <= '9');
return ret - buf;
}
|