#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <poll.h>

char buf[1024];
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[] = {
		{0, POLLIN, 0},
		{fdin, POLLIN, 0}};
	for (;;) {
		poll(pfd, 2, -1);
		if (pfd[0].revents & POLLIN) {
			int n = read(0, buf, 1024);
			if (n == 0) return 0;
			write(fdout, buf, n);
		}
		if (pfd[1].revents & POLLHUP) return 0;
		if (pfd[1].revents & POLLIN) {
			int n = read(fdin, buf, 1024);
			if (n == 0) return 0;
			write(1, buf, n);
		}
	}
}


