- while (!feof(stdin)) {
- n = fread(buffer, 1, sizeof(buffer), stdin);
- if (fwrite(buffer, 1, n, infile) != n)
+ fd = dup(fileno(infile));
+ fclose(infile);
+ if (fd < 0)
+ return NULL;
+
+ n = read(STDIN_FILENO, buffer, sizeof(buffer));
+ while (n > 0) {
+ if (write(fd, buffer, n) != n)