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

int
fd2path(int fd, char *buf, int nbuf)
{
	volatile int ret;
	volatile Chan *c;

	ret = -1;
	c = nil;
	checkerrstack();
	if(!waserror()){
		c = fd2chan(fd, -1);
		utfecpy(buf, buf+nbuf, c->path);
		poperror();
		ret = 0;
	}
	if(c)
		cclose(c);
	checkerrstack();
	return ret;
}


syntax highlighted by Code2HTML, v. 0.9.1