File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -954,7 +954,7 @@ fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
954954isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
955955```
956956
957- 这是因为我们使用了newlib的标准输入输出函数,那么就需要把newlib中其它的系统调用也实现。加入一些简单的什么都不做的桩函数 :
957+ 这是因为我们使用了newlib的标准输入输出函数,那么就需要把newlib中其它的系统调用也实现。除了_sbrk之外我们可以加入一些简单的什么都不做的桩函数。而_sbrk会在printf()函数中使用malloc()的时候被调用到,所以它需要被实现 :
958958
959959``` c
960960int _fstat (int fd, struct stat * st) {
@@ -963,8 +963,13 @@ int _fstat(int fd, struct stat *st) {
963963}
964964
965965void * _ sbrk(int incr) {
966- (void) incr;
967- return NULL;
966+ extern char _ end;
967+ static unsigned char * heap = NULL;
968+ unsigned char * prev_heap;
969+ if (heap == NULL) heap = (unsigned char * ) &_ end;
970+ prev_heap = heap;
971+ heap += incr;
972+ return prev_heap;
968973}
969974
970975int _ close(int fd) {
You can’t perform that action at this time.
0 commit comments