1 | /* Copyright (c) 2004, 2009 Xilinx, Inc. All rights reserved. |
---|
2 | |
---|
3 | Redistribution and use in source and binary forms, with or without |
---|
4 | modification, are permitted provided that the following conditions are |
---|
5 | met: |
---|
6 | |
---|
7 | 1. Redistributions source code must retain the above copyright notice, |
---|
8 | this list of conditions and the following disclaimer. |
---|
9 | |
---|
10 | 2. Redistributions in binary form must reproduce the above copyright |
---|
11 | notice, this list of conditions and the following disclaimer in the |
---|
12 | documentation and/or other materials provided with the distribution. |
---|
13 | |
---|
14 | 3. Neither the name of Xilinx nor the names of its contributors may be |
---|
15 | used to endorse or promote products derived from this software without |
---|
16 | specific prior written permission. |
---|
17 | |
---|
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS |
---|
19 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
---|
20 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
---|
21 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
---|
24 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
25 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
26 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
27 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
29 | |
---|
30 | */ |
---|
31 | |
---|
32 | #include <errno.h> |
---|
33 | |
---|
34 | extern char _heap_start[]; |
---|
35 | extern char _heap[]; |
---|
36 | extern char _heap_end[]; |
---|
37 | |
---|
38 | static char *heap_ptr; |
---|
39 | |
---|
40 | char *sbrk (int nbytes) |
---|
41 | { |
---|
42 | char *base; |
---|
43 | |
---|
44 | if (!heap_ptr) |
---|
45 | heap_ptr = (char *)&_heap; |
---|
46 | |
---|
47 | base = heap_ptr; |
---|
48 | heap_ptr += nbytes; |
---|
49 | |
---|
50 | if (heap_ptr <= ((char *)&_heap_end + 1)) |
---|
51 | return base; |
---|
52 | else |
---|
53 | { |
---|
54 | errno = ENOMEM; |
---|
55 | return ((char *)-1); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|