Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/*
2
 * pANS stdio -- sclose
3
 */
4
#include "iolib.h"
5
char *sclose(FILE *f){
6
	switch(f->state){
7
	default:	/* ERR CLOSED */
8
		if(f->buf && f->flags&BALLOC)
9
			free(f->buf);
10
		f->flags=0;
11
		return NULL;
12
	case OPEN:
13
		f->buf=malloc(1);
14
		f->buf[0]='\0';
15
		break;
16
	case RD:
17
	case END:
18
		f->flags=0;
19
		break;
20
	case RDWR:
21
	case WR:
22
		if(f->wp==f->rp){
23
			if(f->flags&BALLOC)
24
				f->buf=realloc(f->buf, f->bufl+1);
25
			if(f->buf==NULL) return NULL;
26
		}
27
		*f->wp='\0';
28
		f->flags=0;
29
		break;
30
	}
31
	f->state=CLOSED;
32
	f->flags=0;
33
	return f->buf;
34
}