2 #include <fcntl.h> /* file control functions */
5 int main(int argc, char *argv[])
13 if ((argc - optind) != 2) { /* There must two argument */
14 printf("Wrong number of arguments %d\n", argc - optind);
17 /* open pipe, input and output file */
18 in_fd = open(argv[optind], O_RDONLY);
20 printf("Input error %s on %s\n", strerror(errno), argv[optind]);
23 out_fd = open(argv[optind+1], O_CREAT|O_RDWR|O_TRUNC, 0644);
25 printf("Cannot open %s, error %s\n", argv[optind+1], strerror(errno));
28 if (pipe(pipefd) == -1) {
29 perror("Cannot create buffer pipe");
34 nread = splice(in_fd, NULL, pipefd[1], NULL, size,
35 SPLICE_F_MOVE|SPLICE_F_MORE);
36 if (nread == 0) break;
46 nwrite = splice(pipefd[0], NULL, out_fd, NULL, nread,
47 SPLICE_F_MOVE|SPLICE_F_MORE);
52 perror("write error");