source: trunk/minix/lib/other/_brk.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.1 KB
Line 
1#include <lib.h>
2#define brk _brk
3#define sbrk _sbrk
4#include <unistd.h>
5
6extern char *_brksize;
7
8/* Both OSF/1 and SYSVR4 man pages specify that brk(2) returns int.
9 * However, BSD4.3 specifies that brk() returns char*. POSIX omits
10 * brk() on the grounds that it imposes a memory model on an architecture.
11 * For this reason, brk() and sbrk() are not in the lib/posix directory.
12 * On the other hand, they are so crucial to correct operation of so many
13 * parts of the system, that we have chosen to hide the name brk using _brk,
14 * as with system calls. In this way, if a user inadvertently defines a
15 * procedure brk, MINIX may continue to work because the true call is _brk.
16 */
17PUBLIC int brk(addr)
18char *addr;
19{
20 message m;
21
22 if (addr != _brksize) {
23 m.m1_p1 = addr;
24 if (_syscall(MM, BRK, &m) < 0) return(-1);
25 _brksize = m.m2_p1;
26 }
27 return(0);
28}
29
30
31PUBLIC char *sbrk(incr)
32int incr;
33{
34 char *newsize, *oldsize;
35
36 oldsize = _brksize;
37 newsize = _brksize + incr;
38 if ((incr > 0 && newsize < oldsize) || (incr < 0 && newsize > oldsize))
39 return( (char *) -1);
40 if (brk(newsize) == 0)
41 return(oldsize);
42 else
43 return( (char *) -1);
44}
Note: See TracBrowser for help on using the repository browser.