#include	"all.h"
#include	<fio.h>

Fflush(int fd)
{
	Fbuffer *f;

	FIOSET(f, fd);
	return _F_flush(f, fd);
}

_F_flush(Fbuffer *f, int fd)
{
	long n;

	if(f->flags & FIO_WRITING) {
		f->flags &= ~FIO_WRITING;
		if(n = f->next - f->buf){
			if(write(fd, f->buf, n) != n)
				return -1;
			f->next = f->buf;
		}
	}
	return 0;
}
