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
#include <stdlib.h>
6
 
7
char *_IO_sclose(FILE *f){
8
	switch(f->state){
9
	default:	/* ERR CLOSED */
10
		if(f->buf && f->flags&BALLOC)
11
			free(f->buf);
12
		f->state=CLOSED;
13
		f->flags=0;
14
		return NULL;
15
	case OPEN:
16
		f->buf=malloc(1);
17
		f->buf[0]='\0';
18
		break;
19
	case RD:
20
	case END:
21
		f->flags=0;
22
		break;
23
	case RDWR:
24
	case WR:
25
		if(f->wp==f->rp){
26
			if(f->flags&BALLOC)
27
				f->buf=realloc(f->buf, f->bufl+1);
28
			if(f->buf==NULL) return NULL;
29
		}
30
		*f->wp='\0';
31
		f->flags=0;
32
		break;
33
	}
34
	f->state=CLOSED;
35
	f->flags=0;
36
	return f->buf;
37
}