]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/9sys/sbrk.c
88b593e11e2f13803eb41fd76751f8b583fb5fb2
[plan9front.git] / sys / src / libc / 9sys / sbrk.c
1 #include <u.h>
2 #include <libc.h>
3
4 extern  char    end[];
5 static  char    *bloc = { end };
6 extern  int     brk_(void*);
7
8 enum
9 {
10         Round   = 7
11 };
12
13 int
14 brk(void *p)
15 {
16         uintptr bl;
17
18         bl = ((uintptr)p + Round) & ~Round;
19         if(brk_((void*)bl) < 0)
20                 return -1;
21         bloc = (char*)bl;
22         return 0;
23 }
24
25 void*
26 sbrk(ulong n)
27 {
28         uintptr bl;
29
30         bl = ((uintptr)bloc + Round) & ~Round;
31         if(brk_((void*)(bl+n)) < 0)
32                 return (void*)-1;
33         bloc = (char*)bl + n;
34         return (void*)bl;
35 }