14 #define BS SPLICE_SIZE
16 static int splice_flags;
18 static int usage(char *name)
20 fprintf(stderr, "%s: [-m] in_file out_file\n", name);
24 static int parse_options(int argc, char *argv[])
28 while ((c = getopt(argc, argv, "m")) != -1) {
31 splice_flags = SPLICE_F_MOVE;
42 int main(int argc, char *argv[])
44 int in_fd, out_fd, pfds[2], index;
47 index = parse_options(argc, argv);
48 if (index == -1 || index + 2 > argc)
49 return usage(argv[0]);
51 in_fd = open(argv[index], O_RDONLY);
53 return error("open input");
55 if (fstat(in_fd, &sb) < 0)
56 return error("stat input");
58 out_fd = open(argv[index + 1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
60 return error("open output");
66 int this_len = min((off_t) BS, sb.st_size);
67 int ret = ssplice(in_fd, NULL, pfds[1], NULL, this_len, 0);
70 return error("splice-in");
76 int written = ssplice(pfds[0], NULL, out_fd, NULL, ret, splice_flags);
78 return error("splice-out");