xref: /plan9/sys/src/libstdio/fseeko.c (revision dc5a79c1208f0704eeb474acc990728f8b4854f5)
1 /*
2  * pANS stdio -- fseeko
3  */
4 #include "iolib.h"
fseeko(FILE * f,long long offs,int type)5 int fseeko(FILE *f, long long offs, int type){
6 	switch(f->state){
7 	case ERR:
8 	case CLOSED:
9 		return -1;
10 	case WR:
11 		fflush(f);
12 		break;
13 	case RD:
14 		if(type==1 && f->buf!=f->unbuf)
15 			offs-=f->wp-f->rp;
16 		break;
17 	}
18 	if(f->flags&STRING || seek(f->fd, offs, type)==-1) return -1;
19 	if(f->state==RD) f->rp=f->wp=f->buf;
20 	if(f->state!=OPEN)
21 		f->state=RDWR;
22 	return 0;
23 }
24