Skip to content
Snippets Groups Projects
winjunk.c 1.38 KiB
Newer Older
teuben's avatar
teuben committed
#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;
}

slevy's avatar
 
slevy committed
#include <math.h>
double rint(double v) {
    return floor(v + 0.5);
}

int access(char *fname, int how) {
    FILE *f;
    if(fname == NULL || (f = fopen(fname, "r")) == NULL)
	return -1;
    fclose(f);
    return 0;
}

teuben's avatar
teuben committed
#endif /*WIN32*/