Cygwin: Add new APIs tc[gs]etwinsize()
[newlib-cygwin.git] / newlib / libc / sys / sysmec / sbrk.c
blob80cb431f61534a51d48d4c2e8a992056bd3dceb1
1 #include <_ansi.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include "sys/syscall.h"
6 int errno;
8 int __trap0 ();
10 #define TRAP0(f, p1, p2, p3) __trap0(f, (p1), (p2), (p3))
12 caddr_t
13 _sbrk (size_t incr)
15 extern char end; /* Defined by the linker */
16 static char *heap_end;
17 char *prev_heap_end;
18 #if 0
19 char *sp = (char *)stack_ptr;
20 #else
21 char *sp = (char *)&sp;
22 #endif
24 if (heap_end == 0)
26 heap_end = &end;
28 prev_heap_end = heap_end;
29 if (heap_end + incr > sp)
31 _write (1, "Heap and stack collision\n", 25);
32 abort ();
34 heap_end += incr;
35 return (caddr_t) prev_heap_end;