libc_init.c 317 B

123456789101112131415161718
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. FILE *stdin;
  4. FILE *stdout;
  5. FILE *stderr;
  6. void _libc_init()
  7. {
  8. // 初始化标准流对应的文件描述符
  9. stdin = malloc(sizeof(FILE));
  10. stdout = malloc(sizeof(FILE));
  11. stderr = malloc(sizeof(FILE));
  12. stdin->fd = 0;
  13. stdout->fd = 1;
  14. stderr->fd = 2;
  15. }