struct buf {
	int fildes;
	int nfree;
	char *nextp;
	char buff[512];
};


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

/* SCCS ID INFO */
	"~|^`bufwrt.c	1.2	%O%";
/* SCCS ID INFO */

	p = iobuf;
	n = cnt;

	while (n > (i=p->nfree)) {
		move(addr,p->nextp,i);
		addr =+ i;
		n =- i;
		p->nfree = 0;
		bwflush(p);
	}
	if (n) {
		move(addr,p->nextp,n);
		p->nfree =- n;
		p->nextp =+ n;
	}
	return(cnt);
}


bwflush(iobuf)
struct buf *iobuf;
{
	register struct buf *p;

	p=iobuf;
	xwrite(p->fildes,p->buff,512-p->nfree);
	p->nfree = 512;
	p->nextp = p->buff;
}


bwcrt(iobuf,fd,file,mode)
struct buf *iobuf;
int fd;
char *file;
int mode;
{
	register struct buf *p;

	if (fd<0)
		fd = xcreat(file,mode);
	p=iobuf;
	p->fildes = fd;
	p->nfree = 512;
	p->nextp = p->buff;
}
