5 int strverscmp(const char *l0, const char *r0)
7 const unsigned char *l = (const void *)l0;
8 const unsigned char *r = (const void *)r0;
12 /* Find maximal matching prefix and track its maximal digit
13 * suffix and whether those digits are all zeros. */
14 for (dp=i=0; l[i]==r[i]; i++) {
17 if (!isdigit(c)) dp=i+1, z=1;
21 if (l[dp]!='0' && r[dp]!='0') {
22 /* If we're not looking at a digit sequence that began
23 * with a zero, longest digit string is greater. */
24 for (j=i; isdigit(l[j]); j++)
25 if (!isdigit(r[j])) return 1;
26 if (isdigit(r[j])) return -1;
27 } else if (z && dp<i && (isdigit(l[i]) || isdigit(r[i]))) {
28 /* Otherwise, if common prefix of digit sequence is
29 * all zeros, digits order less than non-digits. */
30 return (unsigned char)(l[i]-'0') - (unsigned char)(r[i]-'0');