2 * Use vmsplice to fill some user memory into a pipe. vmsplice writes
3 * to stdout, so that must be a pipe.
12 #include <sys/types.h>
16 int do_vmsplice(int fd, struct iovec *iov, unsigned long nr_vecs)
18 struct pollfd pfd = { .fd = fd, .events = POLLOUT, };
23 * in a real app you'd be more clever with poll of course,
24 * here we are basically just blocking on output room and
25 * not using the free time for anything interesting.
27 if (poll(&pfd, 1, -1) < 0)
30 written = vmsplice(fd, iov, nr_vecs, 0);
33 return error("vmsplice");
36 int this_len = iov->iov_len;
38 if (this_len > written)
41 iov->iov_len -= this_len;
54 static int usage(char *name)
56 fprintf(stderr, "%s | ...\n", name);
60 int main(int argc, char *argv[])
62 char h[] = "header header header header header header header header";
63 char b[] = "body body body body body body body body body body body";
64 char f[] = "footer footer footer footer footer footer footer footer";
68 vecs[0].iov_len = strlen(h);
70 vecs[1].iov_len = strlen(b);
72 vecs[2].iov_len = strlen(f);
74 if (check_output_pipe())
75 return usage(argv[0]);
77 return do_vmsplice(STDOUT_FILENO, vecs, 3);