xref: /plan9/sys/src/ape/lib/ap/stdio/fclose.c (revision 3e12c5d1bb89fc02707907988834ef147769ddaf)
1 /*
2  * pANS stdio -- fclose
3  */
4 #include "iolib.h"
fclose(FILE * f)5 int fclose(FILE *f){
6 	int error=0;
7 	if(!f) return EOF;
8 	if(f->state==CLOSED) return EOF;
9 	if(fflush(f)==EOF) error=EOF;
10 	if(f->flags&BALLOC) free(f->buf);
11 	if(!(f->flags&STRING) && close(f->fd)<0) error=EOF;
12 	f->state=CLOSED;
13 	f->flags=0;
14 	return error;
15 }
16