-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvercmp.c
More file actions
37 lines (34 loc) · 784 Bytes
/
vercmp.c
File metadata and controls
37 lines (34 loc) · 784 Bytes
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
/*
* Compare a version string while recognizing precedence of greater version
* numbers that are delimited by periods. This algorithm is far from perfect
* and will only function correctly when arguments are version strings of the
* current BIND versioning scheme.
*/
#include<string.h>
#include"dnsqry.h"
int
vercmp(const char *s1, const char *s2)
{
register char *p1, *p2;
int ret;
ret = strcmp(s1, s2);
p1 = strchr(s1, '.'), p2 = strchr(s2, '.');
if (!(p1 && p2) || ret)
return (ret);
while (p1 && p2) {
ret = strcmp(p1, p2);
if (ret)
return (ret);
p1 = strchr(p1 + 1, '.'), p2 = strchr(p2 + 1, '.');
}
switch (p1 != NULL) {
case 0:
if (p2)
return (-1);
return (0);
default:
return (1);
}
/* Sedate compiler complaints. */
return (0);
}