#include <9pm/u.h>
#include <9pm/libc.h>
#include <9pm/fcall.h>
#include <9pm/ns.h>

long
pwrite(int fd, void *a, long n, vlong o)
{
	volatile Chan *c;
	volatile long m;

	checkerrstack();
	m = -1;
	c = nil;
	if(!waserror()){
		c = fd2chan(fd, OWRITE);
		m = (*c->mnt->dev->_pwrite)(c, a, n, o);
		poperror();
	}
	if(c)
		cclose(c);
	checkerrstack();
	return m;
}
