home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
LIBSRC.ZOO
/
libsrc
/
local
/
sbrk.c
< prev
next >
Wrap
Text File
|
1992-03-14
|
951b
|
38 lines
#define INCL_DOSMEMMGR
#include <os2.h>
#include <errno.h>
ULONG Dos32SetMem() asm ("Dos32SetMem");
extern char *__first_uncommited_block;
extern char *__first_uncommited_byte;
char *sbrk (int incr)
{
ULONG rc;
char *tmp;
int nblocks;
int diff;
if (incr == 0)
return (__first_uncommited_byte);
tmp = __first_uncommited_byte;
if ((__first_uncommited_byte += incr) > __first_uncommited_block) {
diff = __first_uncommited_byte - __first_uncommited_block;
nblocks = diff / getpagesize() + (diff % getpagesize() ? 1 : 0);
rc = Dos32SetMem (__first_uncommited_block,
nblocks * getpagesize(),
PAG_COMMIT | PAG_READ | PAG_WRITE);
if (rc) {
errno = ENOMEM;
return ((char *)-1);
}
__first_uncommited_block += nblocks * getpagesize();
}
return (tmp);
}