fclose.c 395 B

12345678910111213141516171819202122232425
  1. #include "stdio_impl.h"
  2. int fclose(FILE *f)
  3. {
  4. int r;
  5. int perm;
  6. FFINALLOCK(f);
  7. if (!(perm = f->flags & F_PERM)) {
  8. OFLLOCK();
  9. if (f->prev) f->prev->next = f->next;
  10. if (f->next) f->next->prev = f->prev;
  11. if (libc.ofl_head == f) libc.ofl_head = f->next;
  12. OFLUNLOCK();
  13. }
  14. r = fflush(f);
  15. r |= f->close(f);
  16. if (f->getln_buf) free(f->getln_buf);
  17. if (!perm) free(f);
  18. return r;
  19. }