Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: d90027e0bb
Fetching contributors…

Cannot retrieve contributors at this time

file 46 lines (37 sloc) 0.946 kb
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

#include "version_compare.h"

int compar_version(const void *va,const void *vb) {
const char * const *a = va;
const char * const *b = vb;
return version_compare(*a, *b);
}

int version_compare(const char * a, const char * b) {
char *at, *bt;
int aval, bval;

a = strpbrk(a, "0123456789");
b = strpbrk(b, "0123456789");

while(a && b) {
aval = strtol(a, &at, 10);
bval = strtol(b, &bt, 10);

if(aval != bval) {
return bval - aval;
}

a = strpbrk(at, "0123456789");
b = strpbrk(bt, "0123456789");
}

/* If we fall out of the loop, we've found the end of at least
one version string.
*/
if(a) { /*a has an additional sub-version*/
return -1;
}
if(b) { /*b has an additional sub-version*/
return 1;
}

/* If we get here, we haven't found any differences in versions
(except possibly different delimiters, which we ignore)
*/
return 0;
}
Something went wrong with that request. Please try again.