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 * p,ulong n)39 realloc(void *p, ulong n)
40 {
41 fprint(2, "realloc(0x%p %ld) called\n", p, 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 * v,ulong pc)53 setmalloctag(void *v, ulong pc)
54 {
55 USED(v, pc);
56 }
57
58 int
fileexists(char * s)59 fileexists(char *s)
60 {
61 uchar dirbuf[400];
62
63 /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
64 return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
65 }
66