From: Jens Axboe Date: Mon, 24 Apr 2006 12:23:24 +0000 (+0200) Subject: [PATCH] vmsplice: add clear option (-c) X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=dbcd088397e98ca338191d8930ab2668b6f9a8c2;p=splice.git [PATCH] vmsplice: add clear option (-c) --- diff --git a/vmsplice.c b/vmsplice.c index 9cad246..74780e5 100644 --- a/vmsplice.c +++ b/vmsplice.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -23,6 +25,8 @@ #define ALIGN(buf) (buf) #endif +static int do_clear; + int do_vmsplice(int fd, void *buffer, int len) { struct pollfd pfd = { .fd = fd, .events = POLLOUT, }; @@ -49,6 +53,30 @@ int do_vmsplice(int fd, void *buffer, int len) return 0; } +static int usage(char *name) +{ + fprintf(stderr, "%s: [-c]\n", name); + return 1; +} + +static int parse_options(int argc, char *argv[]) +{ + int c, index = 1; + + while ((c = getopt(argc, argv, "m")) != -1) { + switch (c) { + case 'c': + do_clear = 1; + index++; + break; + default: + return -1; + } + } + + return index; +} + int main(int argc, char *argv[]) { unsigned char *buffer; @@ -56,6 +84,9 @@ int main(int argc, char *argv[]) long page_size; int i, ret; + if (parse_options(argc, argv) < 0) + return usage(argv[0]); + if (fstat(STDOUT_FILENO, &sb) < 0) return error("stat"); if (!S_ISFIFO(sb.st_mode)) { @@ -100,6 +131,14 @@ int main(int argc, char *argv[]) * the buffer, but we do now know that all parts of the first * half have been consumed from the pipe - so we can reuse that. */ + + /* + * Test option - clear the first half of the buffer, should + * be safe now + */ + if (do_clear) + memset(buffer, 0x00, SPLICE_SIZE); + } while (0); return 0;