X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2Fsplicecp.c;h=cbaa4e89725c1746f4a542ecd6aa1bcf5fe4e088;hp=c19066fad7de0ee16208e3897bda299773ce3331;hb=26f7a8bb19c6cb198c213757a97b6ac79e40db4b;hpb=45633dbe15fd23b17a975eb4d9c231d22a67ac00 diff --git a/sources/splicecp.c b/sources/splicecp.c index c19066f..cbaa4e8 100644 --- a/sources/splicecp.c +++ b/sources/splicecp.c @@ -89,10 +89,6 @@ int main(int argc, char *argv[]) usage(); } /* open pipe, input and output file */ - if (pipe(pipefd) == -1) { - perror("Cannot create buffer pipe"); - exit(EXIT_FAILURE); - } in_fd = open(argv[optind], O_RDONLY); if (in_fd < 0) { printf("Input error %s on %s\n", strerror(errno), argv[optind]); @@ -103,10 +99,15 @@ int main(int argc, char *argv[]) printf("Cannot open %s, error %s\n", argv[optind+1], strerror(errno)); exit(EXIT_FAILURE); } + if (pipe(pipefd) == -1) { + perror("Cannot create buffer pipe"); + exit(EXIT_FAILURE); + } /* copy loop */ debug("Size %d\n", size); while (1) { - nread = splice(in_fd, NULL, pipefd[1], NULL, size, 0); + nread = splice(in_fd, NULL, pipefd[1], NULL, size, + SPLICE_F_MOVE|SPLICE_F_MORE); debug("read %d bytes\n", nread); if (nread == 0) break; if (nread < 0) { @@ -117,10 +118,10 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } } - do { - nwrite = splice(pipefd[0], NULL, out_fd, NULL, nread, 0); + while (nread > 0) { + nwrite = splice(pipefd[0], NULL, out_fd, NULL, nread, + SPLICE_F_MOVE|SPLICE_F_MORE); debug("write %d bytes\n", nwrite); - if (nwrite == 0) continue; if (nwrite < 0) { if (errno == EINTR) continue; @@ -131,7 +132,7 @@ int main(int argc, char *argv[]) } nread -= nwrite; debug("left %d bytes\n", nread); - } while (nread); + } } return EXIT_SUCCESS; }