11 int main(int argc, char *argv[])
14 * Variables definition
21 * Input section: decode command line parameters
24 opterr = 0; /* don't want writing to stderr */
25 while ( (i = getopt(argc, argv, "h")) != -1) {
30 case 'h': /* help option */
31 printf("Wrong -h option use\n");
35 case 's': /* take wait time for childen */
36 size = strtol(optarg, NULL, 10); /* convert input */
38 case '?': /* unrecognized options */
39 printf("Unrecognized options -%c\n", optopt);
41 default: /* should not reached */
48 if ((argc - optind) != 1) { /* There must two argument */
49 printf("Wrong number of arguments %d\n", argc - optind);
52 /* open destination file */
53 fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0644);
55 printf("cannot open destination file %s, %s", argv[1],
61 /* copy stdin to stdout */
62 len = tee(STDIN_FILENO, STDOUT_FILENO, size, SPLICE_F_NONBLOCK);
64 if (errno == EAGAIN) {
67 perror("error on tee stdin to stdout");
73 /* write data to the file using splice */
75 nwrite = splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);
77 perror("error on splice stdin to file");