]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/cc/compat
cc: promote integer constants according to c99 spec.
[plan9front.git] / sys / src / cmd / cc / compat
1 int
2 myaccess(char *f)
3 {
4         return access(f, AEXIST);
5 }
6
7 int
8 mycreat(char *n, int p)
9 {
10
11         return create(n, 1, p);
12 }
13
14 int
15 mywait(int *s)
16 {
17         int p;
18         Waitmsg *w;
19
20         if((w = wait()) == nil)
21                 return -1;
22         else{
23                 p = w->pid;
24                 *s = 0;
25                 if(w->msg[0])
26                         *s = 1;
27                 free(w);
28                 return p;
29         }
30 }
31
32 int
33 mydup(int f1, int f2)
34 {
35         return dup(f1,f2);
36 }
37
38 int
39 mypipe(int *fd)
40 {
41         return pipe(fd);
42 }
43
44 int
45 systemtype(int sys)
46 {
47         return sys & Plan9;
48 }
49
50 int
51 pathchar(void)
52 {
53         return '/';
54 }
55
56 char*
57 mygetwd(char *path, int len)
58 {
59         return getwd(path, len);
60 }
61
62 int
63 myexec(char *path, char *argv[])
64 {
65         return exec(path, argv);
66 }
67
68 int
69 myfork(void)
70 {
71         return fork();
72 }
73
74
75 /*
76  * real allocs
77  */
78
79 extern char end[];
80
81 static char*    hunk = end;
82 static long     nhunk;
83 static uintptr  thunk;
84
85 static void
86 gethunk(void)
87 {
88         long nh;
89
90         if(thunk < NHUNK)
91                 nh = NHUNK;
92         else if(thunk < 1000*NHUNK)
93                 nh = thunk;
94         else
95                 nh = 1000*NHUNK;
96
97         if(nhunk < 0)
98                 nhunk = 0;
99         nhunk += nh;
100         thunk += nh;
101         if(brk(hunk+nhunk) < 0)
102                 sysfatal("out of memory");
103 }
104
105 void*
106 alloc(long n)
107 {
108         void *p;
109
110         while((uintptr)hunk & 7) {
111                 hunk++;
112                 nhunk--;
113         }
114         while(nhunk < n)
115                 gethunk();
116         p = hunk;
117         nhunk -= n;
118         hunk += n;
119         return p;
120 }
121
122 void*
123 allocn(void *p, long on, long n)
124 {
125         void *q;
126
127         q = (uchar*)p + on;
128         if(q != hunk || nhunk < n) {
129                 while(nhunk < on+n)
130                         gethunk();
131                 memmove(hunk, p, on);
132                 p = hunk;
133                 hunk += on;
134                 nhunk -= on;
135         }
136         hunk += n;
137         nhunk -= n;
138         return p;
139 }
140
141 /*
142  * fake mallocs
143  */
144 void*
145 malloc(ulong n)
146 {
147         return alloc(n);
148 }
149
150 void*
151 calloc(ulong m, ulong n)
152 {
153         return alloc(m*n);
154 }
155
156 void*
157 realloc(void *o, ulong n)
158 {
159         ulong m;
160         void *a;
161
162         if(n == 0)
163                 return nil;
164         if(o == nil)
165                 return alloc(n);
166         a = alloc(n);
167         m = (char*)a - (char*)o;
168         if(m < n)
169                 n = m;
170         memmove(a, o, n);
171         return a;
172 }
173
174 void
175 free(void*)
176 {
177 }
178
179 /* needed when profiling */
180 void*
181 mallocz(ulong size, int)
182 {
183         return alloc(size);
184 }
185
186 void
187 setmalloctag(void*, uintptr)
188 {
189 }
190
191 void
192 setrealloctag(void*, uintptr)
193 {
194 }