1 #include "l.h" 2 3 /* 4 * fake malloc 5 */ 6 void* 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 22 free(void *p) 23 { 24 USED(p); 25 } 26 27 void* 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* 39 realloc(void*, ulong) 40 { 41 fprint(2, "realloc called\n"); 42 abort(); 43 return 0; 44 } 45 46 void* 47 mysbrk(ulong size) 48 { 49 return sbrk(size); 50 } 51 52 void 53 setmalloctag(void *v, ulong pc) 54 { 55 USED(v, pc); 56 } 57 58 int 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