2 * Use vmsplice to splice data from a pipe to user space memory.
12 #include <sys/types.h>
17 static int splice_flags;
19 int do_vmsplice(int fd, void *buf, int len)
21 struct pollfd pfd = { .fd = fd, .events = POLLIN, };
32 * in a real app you'd be more clever with poll of course,
33 * here we are basically just blocking on output room and
34 * not using the free time for anything interesting.
36 if (poll(&pfd, 1, -1) < 0)
39 written = vmsplice(fd, &iov, 1, splice_flags);
42 return error("vmsplice");
49 iov.iov_len -= written;
50 iov.iov_base += written;
57 static int usage(char *name)
59 fprintf(stderr, "| %s [-d(ump)]\n", name);
63 static int parse_options(int argc, char *argv[])
67 while ((c = getopt(argc, argv, "d")) != -1) {
81 static void hexdump(unsigned char *buf, int len)
85 for (i = 0; i < len; i++)
86 printf("%02x", buf[i]);
90 int main(int argc, char *argv[])
95 if (parse_options(argc, argv) < 0)
96 return usage(argv[0]);
98 if (check_input_pipe())
99 return usage(argv[0]);
103 memset(buf, 0, 4096);
105 ret = do_vmsplice(STDIN_FILENO, buf, 4096);
109 printf("splice %d\n", ret);