#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<poll.h>
#include<sys/stat.h>

int main(int argc, char * argv[]){
	int fdin = open(argv[1], O_RDONLY | O_NONBLOCK);
	int fdout = open(argv[2], O_WRONLY);
	struct pollfd pfd[] = {
		{STDIN_FILENO, POLLIN, 0},
		{fdin, POLLIN, 0}};
#define NPFD sizeof(pfd) / sizeof(*pfd)
	char buf[1024];
	for (;;) {
		int rv = poll(pfd, NPFD, -1);
		ssize_t n;
		if (pfd[0].revents & POLLIN) {
			n = read(STDIN_FILENO, buf, 1024);
			if (n <= 0) break;
			write (fdout, buf, n);
		}
		if (pfd[1].revents & POLLIN) {
			n = read(fdin, buf, 1024);
			if (n <= 0) break;
			write (STDOUT_FILENO, buf, n);
		}
	}
}
