2 * A tee implementation using sys_tee. Stores stdin input in the given file
3 * and duplicates that to stdout.
12 #include <sys/types.h>
19 static int do_splice(int infd, int outfd, unsigned int len, char *msg)
22 int written = splice(infd, NULL, outfd, NULL, len, 0);
33 int main(int argc, char *argv[])
39 fprintf(stderr, "%s: outfile\n", argv[0]);
43 if (fstat(STDIN_FILENO, &sb) < 0)
45 if (!S_ISFIFO(sb.st_mode)) {
46 fprintf(stderr, "stdout must be a pipe\n");
50 fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
52 return error("open output");
55 int tee_len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
58 if (errno == EAGAIN) {
67 * Send output to file, also consumes input pipe.
69 if (do_splice(STDIN_FILENO, fd, tee_len, "splice-file"))