fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / sys / arc / sbrk.c
blob9f863cded6e3854add36de3a196318ff06fc0b68
1 /* sbrk support */
3 /* The current plan is to have one sbrk handler for all cpus.
4 Hence use `asm' for each global variable here to avoid the cpu prefix.
5 We can't intrude on the user's namespace (another reason to use asm). */
7 #include <sys/types.h>
8 #include <sys/syscall.h>
9 #include <errno.h>
10 #include <stddef.h>
12 /* These variables are publicly accessible for debugging purposes.
13 The user is also free to set sbrk_size to something different.
14 See mem-layout.c. */
16 extern int sbrk_size asm ("sbrk_size");
18 caddr_t sbrk_start asm ("sbrk_start");
19 caddr_t sbrk_loc asm ("sbrk_loc");
21 /*caddr_t _sbrk_r (struct _reent *, size_t) asm ("__sbrk_r");*/
23 /* FIXME: We need a semaphore here. */
25 caddr_t
26 _sbrk_r (struct _reent *r, size_t nbytes)
28 caddr_t result;
30 if (
31 /* Ensure we don't underflow. */
32 sbrk_loc + nbytes < sbrk_start
33 /* Ensure we don't overflow. */
34 || sbrk_loc + nbytes > sbrk_start + sbrk_size)
36 errno = ENOMEM;
37 return ((caddr_t) -1);
40 result = sbrk_loc;
41 sbrk_loc += nbytes;
42 return result;