174a4d8c2SCharles.Forsyth #include "l.h"
274a4d8c2SCharles.Forsyth
374a4d8c2SCharles.Forsyth /*
474a4d8c2SCharles.Forsyth * fake malloc
574a4d8c2SCharles.Forsyth */
674a4d8c2SCharles.Forsyth void*
malloc(ulong n)7*45a20ab7Sforsyth malloc(ulong n)
874a4d8c2SCharles.Forsyth {
974a4d8c2SCharles.Forsyth void *p;
1074a4d8c2SCharles.Forsyth
1174a4d8c2SCharles.Forsyth while(n & 7)
1274a4d8c2SCharles.Forsyth n++;
1374a4d8c2SCharles.Forsyth while(nhunk < n)
1474a4d8c2SCharles.Forsyth gethunk();
1574a4d8c2SCharles.Forsyth p = hunk;
1674a4d8c2SCharles.Forsyth nhunk -= n;
1774a4d8c2SCharles.Forsyth hunk += n;
1874a4d8c2SCharles.Forsyth return p;
1974a4d8c2SCharles.Forsyth }
2074a4d8c2SCharles.Forsyth
2174a4d8c2SCharles.Forsyth void
free(void * p)2274a4d8c2SCharles.Forsyth free(void *p)
2374a4d8c2SCharles.Forsyth {
2474a4d8c2SCharles.Forsyth USED(p);
2574a4d8c2SCharles.Forsyth }
2674a4d8c2SCharles.Forsyth
2774a4d8c2SCharles.Forsyth void*
calloc(ulong m,ulong n)28*45a20ab7Sforsyth calloc(ulong m, ulong n)
2974a4d8c2SCharles.Forsyth {
3074a4d8c2SCharles.Forsyth void *p;
3174a4d8c2SCharles.Forsyth
3274a4d8c2SCharles.Forsyth n *= m;
3374a4d8c2SCharles.Forsyth p = malloc(n);
3474a4d8c2SCharles.Forsyth memset(p, 0, n);
3574a4d8c2SCharles.Forsyth return p;
3674a4d8c2SCharles.Forsyth }
3774a4d8c2SCharles.Forsyth
3874a4d8c2SCharles.Forsyth void*
realloc(void *,ulong)39*45a20ab7Sforsyth realloc(void*, ulong)
4074a4d8c2SCharles.Forsyth {
41*45a20ab7Sforsyth fprint(2, "realloc called\n");
4274a4d8c2SCharles.Forsyth abort();
4374a4d8c2SCharles.Forsyth return 0;
4474a4d8c2SCharles.Forsyth }
4574a4d8c2SCharles.Forsyth
4674a4d8c2SCharles.Forsyth void*
mysbrk(ulong size)4774a4d8c2SCharles.Forsyth mysbrk(ulong size)
4874a4d8c2SCharles.Forsyth {
4974a4d8c2SCharles.Forsyth return sbrk(size);
5074a4d8c2SCharles.Forsyth }
51*45a20ab7Sforsyth
52*45a20ab7Sforsyth void
setmalloctag(void * v,ulong pc)53*45a20ab7Sforsyth setmalloctag(void *v, ulong pc)
54*45a20ab7Sforsyth {
55*45a20ab7Sforsyth USED(v, pc);
56*45a20ab7Sforsyth }
57*45a20ab7Sforsyth
58*45a20ab7Sforsyth int
fileexists(char * s)59*45a20ab7Sforsyth fileexists(char *s)
60*45a20ab7Sforsyth {
61*45a20ab7Sforsyth uchar dirbuf[400];
62*45a20ab7Sforsyth
63*45a20ab7Sforsyth /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
64*45a20ab7Sforsyth return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
65*45a20ab7Sforsyth }
66