__stdio_exit.c 511 B

1234567891011121314151617181920212223
  1. #include "stdio_impl.h"
  2. static FILE *const dummy_file = 0;
  3. weak_alias(dummy_file, __stdin_used);
  4. weak_alias(dummy_file, __stdout_used);
  5. weak_alias(dummy_file, __stderr_used);
  6. static void close_file(FILE *f)
  7. {
  8. if (!f) return;
  9. FFINALLOCK(f);
  10. if (f->wpos > f->wbase) f->write(f, 0, 0);
  11. if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR);
  12. }
  13. void __stdio_exit(void)
  14. {
  15. FILE *f;
  16. OFLLOCK();
  17. for (f=libc.ofl_head; f; f=f->next) close_file(f);
  18. close_file(__stdin_used);
  19. close_file(__stdout_used);
  20. }