mailing list of musl libc
 help / color / mirror / code / Atom feed
33a42eed1162fb15b2d9e4387775dba087f5d5ef blob 680 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
#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 {
			return (lenl - lenr);
		}
	} else {
		return (*l -  *r);
	}
}
debug log:

solving 33a42ee ...
found 33a42ee in https://git.vuxu.org/mirror/musl/

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).