X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstring%2Fstrverscmp.c;h=33a42eed1162fb15b2d9e4387775dba087f5d5ef;hp=7054967837f895301d5472ec9303ff63905db6ed;hb=4853c1f7f7b5023aa6a409abc1e759f5f92c9c4e;hpb=a6540174be064806b6eb4dc6abff48a9b4facfdd diff --git a/src/string/strverscmp.c b/src/string/strverscmp.c index 70549678..33a42eed 100644 --- a/src/string/strverscmp.c +++ b/src/string/strverscmp.c @@ -1,7 +1,40 @@ +#define _GNU_SOURCE +#include #include +#include int strverscmp(const char *l, const char *r) { - /* FIXME */ - return strcmp(l, r); + int haszero=1; + while (*l==*r) { + if (!*l) return 0; + + if (*l=='0') { + if (haszero==1) { + haszero=0; + } + } else if (isdigit(*l)) { + if (haszero==1) { + haszero=2; + } + } else { + haszero=1; + } + l++; r++; + } + if (haszero==1 && (*l=='0' || *r=='0')) { + haszero=0; + } + if ((isdigit(*l) && isdigit(*r) ) && haszero) { + size_t lenl=0, lenr=0; + while (isdigit(l[lenl]) ) lenl++; + while (isdigit(r[lenr]) ) lenr++; + if (lenl==lenr) { + return (*l - *r); + } else { + return (lenl - lenr); + } + } else { + return (*l - *r); + } }