|BRK(2)||Linux Programmer's Manual||BRK(2)|
int brk(void *addr);
void *sbrk(intptr_t increment);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
- Since glibc 2.19:
_DEFAULT_SOURCE || (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200112L)
- From glibc 2.12 to 2.19:
_BSD_SOURCE || _SVID_SOURCE || (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200112L)
- Before glibc 2.12:
- _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500
brk() sets the end of the data segment to the value specified by addr, when that value is reasonable, the system has enough memory, and the process does not exceed its maximum data size (see setrlimit(2)).
sbrk() increments the program's data space by increment bytes. Calling sbrk() with an increment of 0 can be used to find the current location of the program break.
On success, sbrk() returns the previous program break. (If the break was increased, then this value is a pointer to the start of the newly allocated memory). On error, (void *) -1 is returned, and errno is set to ENOMEM.
Various systems use various types for the argument of sbrk(). Common are int, ssize_t, ptrdiff_t, intptr_t.
On Linux, sbrk() is implemented as a library function that uses the brk() system call, and does some internal bookkeeping so that it can return the old break value.