Plan 9 from Bell Labs’s /usr/web/sources/patch/maybe/ape-updates/_IO_getc.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/*
 * 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:
		if(_IO_setvbuf(f) != 0)
			return EOF;
	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);
		if(f->state == CLOSED)
			return EOF;
		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;
		}
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.