xref: /minix/minix/lib/libc/sys/brk.c (revision 7f5f010b)
1 #include <sys/cdefs.h>
2 #include "namespace.h"
3 #include <lib.h>
4 
5 #include <string.h>
6 #include <unistd.h>
7 
8 #ifdef __weak_alias
9 __weak_alias(brk, _brk)
10 #endif
11 
12 extern char *_brksize;
13 
14 /* Both OSF/1 and SYSVR4 man pages specify that brk(2) returns int.
15  * However, BSD4.3 specifies that brk() returns char*.  POSIX omits
16  * brk() on the grounds that it imposes a memory model on an architecture.
17  * On the other hand, they are so crucial to correct operation of so many
18  * parts of the system, that we have chosen to hide the name brk using _brk,
19  * as with system calls.  In this way, if a user inadvertently defines a
20  * procedure brk, MINIX may continue to work because the true call is _brk.
21  */
22 int brk(addr)
23 void *addr;
24 {
25   message m;
26 
27   if (addr != _brksize) {
28 	memset(&m, 0, sizeof(m));
29 	m.m_lc_vm_brk.addr = addr;
30 	if (_syscall(VM_PROC_NR, VM_BRK, &m) < 0) return(-1);
31 	_brksize = addr;
32   }
33   return(0);
34 }
35 
36