_brk.c

Go to the documentation of this file.
00001 #include <lib.h>
00002 #define brk     _brk
00003 #define sbrk    _sbrk
00004 #include <unistd.h>
00005 
00006 extern char *_brksize;
00007 
00008 /* Both OSF/1 and SYSVR4 man pages specify that brk(2) returns int.
00009  * However, BSD4.3 specifies that brk() returns char*.  POSIX omits
00010  * brk() on the grounds that it imposes a memory model on an architecture.
00011  * For this reason, brk() and sbrk() are not in the lib/posix directory.
00012  * On the other hand, they are so crucial to correct operation of so many
00013  * parts of the system, that we have chosen to hide the name brk using _brk,
00014  * as with system calls.  In this way, if a user inadvertently defines a
00015  * procedure brk, MINIX may continue to work because the true call is _brk.
00016  */
00017 PUBLIC int brk(addr)
00018 char *addr;
00019 {
00020   message m;
00021 
00022   if (addr != _brksize) {
00023         m.m1_p1 = addr;
00024         if (_syscall(MM, BRK, &m) < 0) return(-1);
00025         _brksize = m.m2_p1;
00026   }
00027   return(0);
00028 }
00029 
00030 
00031 PUBLIC char *sbrk(incr)
00032 int incr;
00033 {
00034   char *newsize, *oldsize;
00035 
00036   oldsize = _brksize;
00037   newsize = _brksize + incr;
00038   if ((incr > 0 && newsize < oldsize) || (incr < 0 && newsize > oldsize))
00039         return( (char *) -1);
00040   if (brk(newsize) == 0)
00041         return(oldsize);
00042   else
00043         return( (char *) -1);
00044 }

Generated on Fri Apr 14 22:57:26 2006 for minix by  doxygen 1.4.6