2 * Use vmsplice to splice data from a pipe to user space memory.
11 #include <sys/types.h>
16 static int splice_flags;
18 int do_vmsplice(int fd, void *buf, int len)
20 struct pollfd pfd = { .fd = fd, .events = POLLIN, };
31 * in a real app you'd be more clever with poll of course,
32 * here we are basically just blocking on output room and
33 * not using the free time for anything interesting.
35 if (poll(&pfd, 1, -1) < 0)
38 written = vmsplice(fd, &iov, 1, splice_flags);
41 return error("vmsplice");
48 iov.iov_len -= written;
49 iov.iov_base += written;
56 static int usage(char *name)
58 fprintf(stderr, "| %s [-d(ump)]\n", name);
62 static int parse_options(int argc, char *argv[])
66 while ((c = getopt(argc, argv, "d")) != -1) {
80 static void hexdump(unsigned char *buf, int len)
84 for (i = 0; i < len; i++)
85 printf("%02x", buf[i]);
89 int main(int argc, char *argv[])
94 if (parse_options(argc, argv) < 0)
95 return usage(argv[0]);
97 if (check_input_pipe())
98 return usage(argv[0]);
102 memset(buf, 0, 4096);
104 ret = do_vmsplice(STDIN_FILENO, buf, 4096);
108 printf("splice %d\n", ret);