File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -1182,8 +1182,10 @@ fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
11821182isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
11831183` ` `
11841184
1185- Since we' ve used a newlib stdio function, we need to supply newlib with the rest
1186- of syscalls. Let' s add just a simple stubs that do nothing:
1185+ Since we' ve used a newlib stdio function, we need to supply newlib with the
1186+ rest of syscalls. We add a simple stubs that do nothing, with exception of
1187+ `_sbrk()`. It needs to be implemented, since `printf()` calls `malloc()` which
1188+ calls `_sbrk()`:
11871189
11881190```c
11891191int _fstat(int fd, struct stat *st) {
@@ -1192,8 +1194,13 @@ int _fstat(int fd, struct stat *st) {
11921194}
11931195
11941196void *_sbrk(int incr) {
1195- (void) incr;
1196- return NULL;
1197+ extern char _end;
1198+ static unsigned char *heap = NULL;
1199+ unsigned char *prev_heap;
1200+ if (heap == NULL) heap = (unsigned char *) &_end;
1201+ prev_heap = heap;
1202+ heap += incr;
1203+ return prev_heap;
11971204}
11981205
11991206int _close(int fd) {
You can’t perform that action at this time.
0 commit comments