fclose.c 286 B

1234567891011121314
  1. /*
  2. * pANS stdio -- fclose
  3. */
  4. #include "iolib.h"
  5. int fclose(FILE *f){
  6. int error=0;
  7. if(f->state==CLOSED) return EOF;
  8. if(fflush(f)==EOF) error=EOF;
  9. if(f->flags&BALLOC) free(f->buf);
  10. if(!(f->flags&STRING) && close(f->fd)<0) error=EOF;
  11. f->state=CLOSED;
  12. f->flags=0;
  13. return error;
  14. }