2 * A tee implementation using sys_tee. Stores stdin input in the given file
3 * and duplicates that to stdout.
11 #include <sys/types.h>
18 static int do_splice(int infd, int outfd, unsigned int len, char *msg)
21 int written = splice(infd, NULL, outfd, NULL, len, 0);
32 static int usage(char *name)
34 fprintf(stderr, "... | %s: outfile\n", name);
38 int main(int argc, char *argv[])
43 return usage(argv[0]);
45 if (check_input_pipe())
46 return usage(argv[0]);
48 fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
50 return error("open output");
53 int tee_len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
56 if (errno == EAGAIN) {
65 * Send output to file, also consumes input pipe.
67 if (do_splice(STDIN_FILENO, fd, tee_len, "splice-file"))