xref: /inferno-os/utils/ld/Plan9.c (revision 9dbf735d35c339c90deaed43fc0ae17f16c122f7)
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 *p, ulong n)
40 {
41 	USED(p);
42 	USED(n);
43 	fprint(2, "realloc called\n");
44 	abort();
45 	return 0;
46 }
47 
48 void*
49 mysbrk(ulong size)
50 {
51 	return sbrk(size);
52 }
53 
54 void
55 setmalloctag(void*, ulong)
56 {
57 }
58 
59 int
60 fileexists(char *s)
61 {
62 	uchar dirbuf[400];
63 
64 	/* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
65 	return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
66 }
67