-
Notifications
You must be signed in to change notification settings - Fork 1
/
chkver.c
91 lines (68 loc) · 1.37 KB
/
chkver.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include"dnsqry.h"
int
chkver(const char *fullver, const char *fullcon)
{
register const char *p, *op;
char *ver, retcode = 0;
for (p = (const char *)fullcon; *p; p++) {
switch (*p) {
case '<':
op = ++p;
while (isalnum(*p) || *p == '.' || *p == '-')
p++;
if (!(ver = (char *)malloc(p - op + 1)))
vexit("malloc");
strncpy(ver, op, p - op);
*(ver + (p - op)) = 0;
ver=genver(ver);
if (vercmp(fullver, ver) < 0)
retcode |= 0x1;
else
retcode &= ~0x1;
p--;
break;
case '>':
op = ++p;
while (isalnum(*p) || *p == '.' || *p == '-')
p++;
if (!(ver = (char *)malloc(p - op + 1)))
vexit("malloc");
strncpy(ver, op, p - op);
*(ver + (p - op)) = 0;
ver=genver(ver);
if (vercmp(fullver, ver) > 0)
retcode |= 0x1;
else
retcode &= ~0x1;
p--;
break;
case '=':
op = ++p;
while (isalnum(*p) || *p == '.' || *p == '-')
p++;
if (!(ver = (char *)malloc(p - op + 1)))
vexit("malloc");
strncpy(ver, op, p - op);
*(ver + (p - op)) = 0;
ver=genver(ver);
if (!vercmp(fullver, ver))
retcode |= 0x1;
else
retcode &= ~0x1;
p--;
break;
case '|':
if (retcode & 0x1)
return (1);
break;
case '&':
if (!(retcode & 0x1))
return (0);
break;
}
}
return (retcode & 0x1);
}