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 #define S1 "header header header header header header header header"
61 #define S2 "body body body body body body body body body body body"
62 #define S3 "footer footer footer footer footer footer footer footer"
64 int main(int argc, char *argv[])
68 /* Dangerous on-stack usage! */
77 vecs[0].iov_base = strdup(S1);
78 vecs[1].iov_base = strdup(S2);
79 vecs[2].iov_base = strdup(S3);
81 vecs[0].iov_len = strlen(vecs[0].iov_base);
82 vecs[1].iov_len = strlen(vecs[1].iov_base);
83 vecs[2].iov_len = strlen(vecs[2].iov_base);
86 if (check_output_pipe())
87 return usage(argv[0]);
89 return do_vmsplice(STDOUT_FILENO, vecs, 3);