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