struct buf {
	int fildes;	/* File descriptor */
	int nleft;	/* Chars left in buffer */
	char *nextp;	/* Ptr to next character */
	char buff[512];	/* The buffer */
};

bufread(iobuf,addr,cnt)
struct buf *iobuf;
char *addr;
int cnt;
{
	register struct buf *p;
	register int n, i;
	int t, rc;

/* SCCS ID INFO */
	"~|^`bufrd.c	1.3	%O%";
/* SCCS ID INFO */
	rc = 0;
	p = iobuf;
	n = cnt;

	while ((t = (i = p->nleft)-n)<=0) {
		move(p->nextp,addr,i);
		n =- i;
		rc =+ i;
		addr =+ i;
		if((p->nleft = read(p->fildes,p->nextp = iobuf->buff,512))<0)
			return(-1);
		else if (p->nleft==0) return(rc);
	}

	if (n) {
		move(p->nextp,addr,n);
		p->nleft = t;
		p->nextp =+ n;
		rc =+ n;
	}
	return(rc);
}


brinit(iobuf,fd)
struct buf *iobuf;
int fd;
{
	register struct buf *p;

	p = iobuf;
	p->fildes = fd;
	p->nleft = 0;
	p->nextp = p->buff;
}
