1 /* sbrk.c - Change data segment size */
3 /* Written 2000 by Werner Almesberger */
4 /* Modified 2003-2004 for klibc by H. Peter Anvin */
12 char *__current_brk; /* Common with brk.c */
14 /* p is an address, a is alignment; must be a power of 2 */
15 static inline void *align_up(void *p, uintptr_t a)
17 return (void *) (((uintptr_t)p + a-1) & ~(a-1));
20 void *sbrk(ptrdiff_t increment)
22 char *start, *end, *new_brk;
25 __current_brk = __brk(NULL);
27 start = align_up(__current_brk, SBRK_ALIGNMENT);
28 end = start + increment;
32 if (new_brk == (void *)-1)
34 else if (new_brk < end) {
39 __current_brk = new_brk;