home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / local / sbrk.c < prev    next >
Text File  |  1992-03-14  |  951b  |  38 lines

  1. #define INCL_DOSMEMMGR
  2. #include <os2.h>
  3. #include <errno.h>
  4.  
  5. ULONG Dos32SetMem() asm ("Dos32SetMem");
  6.  
  7. extern char *__first_uncommited_block;
  8. extern char *__first_uncommited_byte;
  9.  
  10. char *sbrk (int incr)
  11. {
  12.    ULONG rc;
  13.    char *tmp;
  14.    int nblocks;
  15.    int diff;
  16.  
  17.    if (incr == 0)
  18.       return (__first_uncommited_byte);
  19.  
  20.    tmp = __first_uncommited_byte;
  21.  
  22.    if ((__first_uncommited_byte += incr) > __first_uncommited_block) {
  23.       diff = __first_uncommited_byte - __first_uncommited_block;
  24.       nblocks = diff / getpagesize() + (diff % getpagesize() ? 1 : 0);
  25.       rc = Dos32SetMem (__first_uncommited_block,
  26.                                       nblocks * getpagesize(),
  27.                                       PAG_COMMIT | PAG_READ | PAG_WRITE);
  28.       if (rc) {
  29.          errno = ENOMEM;
  30.          return ((char *)-1);
  31.       }
  32.       __first_uncommited_block += nblocks * getpagesize();
  33.    }
  34.  
  35.    return (tmp);
  36. }
  37.  
  38.