shithub: riscv

ref: 3a41ce3bf314caad67c2c52a06142f7ac60611c7
dir: /sys/src/cmd/upas/fs/extra/fd2path.c/

View raw version
#include <u.h>
#include <libc.h>

void
usage(void)
{
	fprint(2, "usage: fd2path path ...\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	char buf[1024];
	int fd;

	ARGBEGIN{
	default:
		usage();
	}ARGEND

	if(argc == 0){
		if(fd2path(0, buf, sizeof buf) != -1)
			fprint(2, "%s\n", buf);
	}else for(; *argv; argv++){
		fd = open(*argv, OREAD);
		if(fd != -1 && fd2path(fd, buf, sizeof buf) != -1)
			fprint(2, "%s\n", buf);
		close(fd);
	}
	exits("");
}