Newer
Older
/*
* Assorted functions needed for Windows port.
* Stuart Levy, slevy@ncsa.uiuc.edu
* National Center for Supercomputing Applications,
* University of Illinois 2001.
* This file is part of partiview, released under the
* Illinois Open Source License; see the file LICENSE.partiview for details.
#ifndef HAVE_STRCASECMP
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
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;
}
#endif /*!HAVE_STRCASECMP*/
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;
}
#endif /*!HAVE_RINT*/
#ifndef HAVE_SNPRINTF
/* Use FLTK's substitute vsnprintf since Win32 lacks any of its own */
extern int fl_vsnprintf(char* str, size_t size, const char* fmt, va_list ap);
int snprintf(char* str, size_t size, const char* fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
ret = fl_vsnprintf(str, size, fmt, ap);
va_end(ap);
return ret;
}
#endif /*!HAVE_SNPRINTF*/