blob: 71be3fd03d9e4c818e6701242f34831235b756a5 (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#include <windows.h>
#include <lib9.h>
/*
* We can't include l.h, because Windoze wants to use some names
* like FLOAT and ABC which we declare. Define what we need here.
*/
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
extern char *hunk;
extern long nhunk;
void gethunk(void);
/*
* fake malloc
*/
void*
malloc(uint n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
}
void*
calloc(uint m, uint n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void *p, uint n)
{
void *new;
new = malloc(n);
if(new && p)
memmove(new, p, n);
return new;
}
#define Chunk (1*1024*1024)
void*
mysbrk(ulong size)
{
void *v;
static int chunk;
static uchar *brk;
if(chunk < size) {
chunk = Chunk;
if(chunk < size)
chunk = Chunk + size;
brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if(brk == 0)
return (void*)-1;
}
v = brk;
chunk -= size;
brk += size;
return v;
}
double
cputime(void)
{
return ((double)0);
}
int
fileexists(char *name)
{
int fd;
fd = open(name, OREAD);
if(fd < 0)
return 0;
close(fd);
return 1;
}
|