2011-03-30 15:46:40 +03:00
|
|
|
/*
|
|
|
|
* pANS stdio -- _IO_getc
|
|
|
|
*/
|
|
|
|
#include "iolib.h"
|
|
|
|
int _IO_getc(FILE *f){
|
|
|
|
int cnt, n;
|
|
|
|
switch(f->state){
|
|
|
|
default: /* CLOSED, WR, ERR, EOF */
|
|
|
|
return EOF;
|
|
|
|
case OPEN:
|
2013-03-11 00:48:35 +01:00
|
|
|
if(_IO_setvbuf(f)!=0) return EOF;
|
2011-03-30 15:46:40 +03:00
|
|
|
case RDWR:
|
|
|
|
case RD:
|
|
|
|
if(f->flags&STRING) return EOF;
|
|
|
|
if(f->buf == f->unbuf)
|
|
|
|
n = 1;
|
|
|
|
else
|
|
|
|
n = f->bufl;
|
|
|
|
cnt=read(f->fd, f->buf, n);
|
2013-03-11 00:48:35 +01:00
|
|
|
if(f->state==CLOSED) return EOF;
|
2011-03-30 15:46:40 +03:00
|
|
|
switch(cnt){
|
|
|
|
case -1: f->state=ERR; return EOF;
|
|
|
|
case 0: f->state=END; return EOF;
|
|
|
|
default:
|
|
|
|
f->state=RD;
|
|
|
|
f->rp=f->buf;
|
|
|
|
f->wp=f->buf+cnt;
|
|
|
|
return (*f->rp++)&_IO_CHMASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|