| 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) |
| 251 |
|
n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1); /* word align rqst. */ |
| 252 |
|
|
| 253 |
|
if (n > nrem) { /* need more core */ |
| 254 |
+ |
tryagain: |
| 255 |
|
if (n > amnt) { /* big chunk */ |
| 256 |
|
thisamnt = (n+(pagesz-1))&~(pagesz-1); |
| 257 |
|
if (thisamnt <= MAXINCR) /* increase amnt */ |
| 260 |
|
thisamnt = amnt; |
| 261 |
|
p = sbrk(thisamnt); |
| 262 |
|
if ((int)p == -1) { /* uh-oh, ENOMEM */ |
| 263 |
< |
thisamnt = n; /* search free lists */ |
| 264 |
< |
p = mscrounge(&thisamnt); |
| 265 |
< |
if (p == NULL) /* we're really out */ |
| 263 |
> |
errno = 0; /* call cavalry */ |
| 264 |
> |
if (thisamnt >= n+pagesz) { |
| 265 |
> |
amnt = pagesz; /* minimize request */ |
| 266 |
> |
goto tryagain; |
| 267 |
> |
} |
| 268 |
> |
thisamnt = n; |
| 269 |
> |
p = mscrounge(&thisamnt); /* search free lists */ |
| 270 |
> |
if (p == NULL) { /* we're really out */ |
| 271 |
> |
errno = ENOMEM; |
| 272 |
|
return(NULL); |
| 273 |
+ |
} |
| 274 |
|
} |
| 275 |
|
#ifdef MSTATS |
| 276 |
|
else b_nsbrked += thisamnt; |