1 #include <windows.h> 2 3 /* 4 * We can't include l.h, because Windoze wants to use some names 5 * like FLOAT and ABC which we declare. Define what we need here. 6 */ 7 typedef unsigned char uchar; 8 typedef unsigned int uint; 9 typedef unsigned long ulong; 10 11 extern char *hunk; 12 extern long nhunk; 13 14 void gethunk(void); 15 16 /* 17 * fake malloc 18 */ 19 void* 20 malloc(uint n) 21 { 22 void *p; 23 24 while(n & 7) 25 n++; 26 while(nhunk < n) 27 gethunk(); 28 p = hunk; 29 nhunk -= n; 30 hunk += n; 31 return p; 32 } 33 34 void 35 free(void *p) 36 { 37 } 38 39 void* 40 calloc(uint m, uint n) 41 { 42 void *p; 43 44 n *= m; 45 p = malloc(n); 46 memset(p, 0, n); 47 return p; 48 } 49 50 void* 51 realloc(void *p, uint n) 52 { 53 void *new; 54 55 new = malloc(n); 56 if(new && p) 57 memmove(new, p, n); 58 return new; 59 } 60 61 #define Chunk (1*1024*1024) 62 63 void* 64 mysbrk(ulong size) 65 { 66 void *v; 67 static int chunk; 68 static uchar *brk; 69 70 if(chunk < size) { 71 chunk = Chunk; 72 if(chunk < size) 73 chunk = Chunk + size; 74 brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 75 if(brk == 0) 76 return (void*)-1; 77 } 78 v = brk; 79 chunk -= size; 80 brk += size; 81 return v; 82 } 83 84 double 85 cputime(void) 86 { 87 return ((double)0); 88 } 89 90 int 91 fileexists(char *name) 92 { 93 int fd; 94 95 fd = open(f, OREAD); 96 if(fd < 0) 97 return 0; 98 close(fd); 99 return 1; 100 } 101