From 4853c1f7f7b5023aa6a409abc1e759f5f92c9c4e Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 26 Feb 2013 01:36:47 -0500 Subject: [PATCH 1/1] implement non-stub strverscmp patch by Isaac Dunham. --- src/string/strverscmp.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) 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); + } } -- 2.20.1