• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifdef __GNUC__
9 #include <stdio.h>
10 #include <errno.h>
11 #include "hpm_common.h"
12 
_sbrk(int incr)13 void *_sbrk(int incr)
14 {
15     extern char __heap_start__, __heap_end__;
16     static char *heap_end;
17     char *prev_heap_end;
18     void *ret;
19 
20     if (heap_end == NULL)
21     {
22         heap_end = &__heap_start__;
23     }
24 
25     prev_heap_end = heap_end;
26 
27     if ((unsigned int)heap_end + (unsigned int)incr > (unsigned int)(&__heap_end__))
28     {
29         errno = ENOMEM;
30 
31         ret = (void *)-1;
32     }
33     else
34     {
35         heap_end = (char *)((unsigned int)heap_end + (unsigned int)incr);
36 
37         ret = (void *)prev_heap_end;
38     }
39 
40     return ret;
41 }
42 #endif
43