24 |
|
|
25 |
|
#include <errno.h> |
26 |
|
|
27 |
– |
extern int errno; |
28 |
– |
|
27 |
|
#ifndef BSD |
28 |
|
#define bcopy(s,d,n) (void)memcpy(d,s,n) |
29 |
|
#define bzero(d,n) (void)memset(d,0,n) |
160 |
|
|
161 |
|
for ( ; ; ) { |
162 |
|
/* compact free lists */ |
163 |
< |
compactfree(); |
163 |
> |
while (compactfree()) |
164 |
> |
; |
165 |
|
/* find largest block */ |
166 |
|
tab = mtab(&cptab); tablen = mtablen(&cptab); |
167 |
|
big = tab; |
252 |
|
n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1); /* word align rqst. */ |
253 |
|
|
254 |
|
if (n > nrem) { /* need more core */ |
255 |
+ |
tryagain: |
256 |
|
if (n > amnt) { /* big chunk */ |
257 |
|
thisamnt = (n+(pagesz-1))&~(pagesz-1); |
258 |
|
if (thisamnt <= MAXINCR) /* increase amnt */ |
261 |
|
thisamnt = amnt; |
262 |
|
p = sbrk(thisamnt); |
263 |
|
if ((int)p == -1) { /* uh-oh, ENOMEM */ |
264 |
< |
thisamnt = n; /* search free lists */ |
265 |
< |
p = mscrounge(&thisamnt); |
266 |
< |
if (p == NULL) /* we're really out */ |
264 |
> |
errno = 0; /* call cavalry */ |
265 |
> |
if (thisamnt >= n+pagesz) { |
266 |
> |
amnt = pagesz; /* minimize request */ |
267 |
> |
goto tryagain; |
268 |
> |
} |
269 |
> |
thisamnt = n; |
270 |
> |
p = mscrounge(&thisamnt); /* search free lists */ |
271 |
> |
if (p == NULL) { /* we're really out */ |
272 |
> |
errno = ENOMEM; |
273 |
|
return(NULL); |
274 |
+ |
} |
275 |
|
} |
276 |
|
#ifdef MSTATS |
277 |
|
else b_nsbrked += thisamnt; |