1 #include "l.h"
2
3 /*
4 * fake malloc
5 */
6 void*
malloc(ulong n)7 malloc(ulong n)
8 {
9 void *p;
10
11 while(n & 7)
12 n++;
13 while(nhunk < n)
14 gethunk();
15 p = hunk;
16 nhunk -= n;
17 hunk += n;
18 return p;
19 }
20
21 void
free(void * p)22 free(void *p)
23 {
24 USED(p);
25 }
26
27 void*
calloc(ulong m,ulong n)28 calloc(ulong m, ulong n)
29 {
30 void *p;
31
32 n *= m;
33 p = malloc(n);
34 memset(p, 0, n);
35 return p;
36 }
37
38 void*
realloc(void *,ulong)39 realloc(void*, ulong)
40 {
41 fprint(2, "realloc called\n");
42 abort();
43 return 0;
44 }
45
46 void*
mysbrk(ulong size)47 mysbrk(ulong size)
48 {
49 return sbrk(size);
50 }
51
52 void
setmalloctag(void *,ulong)53 setmalloctag(void*, ulong)
54 {
55 }
56
57 int
fileexists(char * s)58 fileexists(char *s)
59 {
60 uchar dirbuf[400];
61
62 /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
63 return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
64 }
65