diff options
Diffstat (limited to 'system/lib/libc/musl/src/string/strverscmp.c')
-rw-r--r-- | system/lib/libc/musl/src/string/strverscmp.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/system/lib/libc/musl/src/string/strverscmp.c b/system/lib/libc/musl/src/string/strverscmp.c new file mode 100644 index 00000000..94d2e15c --- /dev/null +++ b/system/lib/libc/musl/src/string/strverscmp.c @@ -0,0 +1,42 @@ +#define _GNU_SOURCE +#include <ctype.h> +#include <string.h> +#include <sys/types.h> + +int strverscmp(const char *l, const char *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 if (lenl>lenr) { + return 1; + } else { + return -1; + } + } else { + return (*l - *r); + } +} |