commit ddf8e4a8099535b61fa7baaa7fae35e18ccf24ae Author: Isaac Dunham Date: Mon Dec 31 12:38:36 2012 -0800 Fix strverscmp. Disagrees with glibc by saying that 00 < 009, but that's a GNU bug. diff --git a/src/string/strverscmp.c b/src/string/strverscmp.c index 7054967..8f3f11f 100644 --- a/src/string/strverscmp.c +++ b/src/string/strverscmp.c @@ -1,7 +1,41 @@ +#define _GNU_SOURCE +#include #include int strverscmp(const char *l, const char *r) { - /* FIXME */ - return strcmp(l, r); + int haszero=1; + while (*l && *r && l[0]==r[0]){ + if (l[0]=='0'){ + if (haszero==1) { + haszero=0; + } + } else if (isdigit(l[0])) { + if (haszero==1) { + haszero=2; + } + } else { + haszero=1; + } + l++; r++; + } + if (haszero==1 && (l[0]=='0' || r[0]=='0')) { + haszero=0; + } + if ((isdigit(l[0]) && isdigit(r[0]) ) && haszero) { + int lenl=0, lenr=0, firstl=l[0], firstr=r[0]; + while (isdigit(l++[0]) ) { + lenl++; + } + while (isdigit(r++[0]) ) { + lenr++; + } + if (lenl==lenr) { + return (firstl - firstr); + } else { + return (lenl - lenr); + } + } else { + return (l[0] - r[0]); + } }