Newer
Older
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
#ifdef WIN32
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int strcasecmp(const char *s1, const char *s2) {
int c1, c2;
if(s1 == NULL) return 1;
if(s2 == NULL) return -1;
for(;;) {
c1 = *s1++;
c2 = *s2++;
if(c1 == '\0')
return (c2 == '\0' ? 0 : 1);
if(c2 == '\0')
return -1;
if(c1 >= 'A' && c1 <= 'Z') c1 += 'a'-'A';
if(c2 >= 'A' && c2 <= 'Z') c2 += 'a'-'A';
if(c1 < c2) return -1;
if(c1 > c2) return 1;
}
}
int strncasecmp(const char *s1, const char *s2, int maxlen) {
int c1, c2;
int i;
if(s1 == NULL) return 1;
if(s2 == NULL) return -1;
for(i = 0; i < maxlen; i++) {
c1 = *s1++;
c2 = *s2++;
if(c1 == '\0')
return (c2 == '\0' ? 0 : 1);
if(c2 == '\0')
return -1;
if(c1 >= 'A' && c1 <= 'Z') c1 += 'a'-'A';
if(c2 >= 'A' && c2 <= 'Z') c2 += 'a'-'A';
if(c1 < c2) return -1;
if(c1 > c2) return 1;
}
return 0;
}
void srandom(int seed) {
srand(seed);
}
int random() {
return rand() << 15 | rand();
}
/* Assuming x86 Windows, i.e. little-endian */
unsigned int htonl(unsigned int v) {
return (v&0xFF)<<24 | (v&0xFF00)<<8 | (v>>8)&0xFF00 | (v>>24)&0xFF;
}
int access(char *fname, int how) {
FILE *f;
if(fname == NULL || (f = fopen(fname, "r")) == NULL)
return -1;
fclose(f);
return 0;
}