Fix various compile warnings
[splice.git] / vmsplice.c
index 72befbe3869430569612bf4a336e49f4374e9f05..2cfe6b29b1e544b609aec6b4d27a34320043fa7e 100644 (file)
@@ -8,8 +8,8 @@
 #include <limits.h>
 #include <string.h>
 #include <getopt.h>
+#include <fcntl.h>
 #include <sys/poll.h>
-#include <sys/stat.h>
 #include <sys/types.h>
 
 #include "splice.h"
@@ -18,6 +18,8 @@
 
 static int do_clear;
 static int align_mask = 65535;
+static int force_unalign;
+static int splice_flags;
 
 int do_vmsplice(int fd, void *b1, void *b2, int len)
 {
@@ -43,13 +45,13 @@ int do_vmsplice(int fd, void *b1, void *b2, int len)
                if (poll(&pfd, 1, -1) < 0)
                        return error("poll");
 
-               written = vmsplice(fd, &iov[idx], 2 - idx, 0);
+               written = svmsplice(fd, &iov[idx], 2 - idx, splice_flags);
 
                if (written <= 0)
                        return error("vmsplice");
 
                len -= written;
-               if (written >= iov[idx].iov_len) {
+               if ((size_t) written >= iov[idx].iov_len) {
                        int extra = written - iov[idx].iov_len;
 
                        idx++;
@@ -66,7 +68,7 @@ int do_vmsplice(int fd, void *b1, void *b2, int len)
 
 static int usage(char *name)
 {
-       fprintf(stderr, "%s: [-c(lear)] [-u(nalign)] | ...\n", name);
+       fprintf(stderr, "%s: [-c(lear)] [-u(nalign)] [-g(ift)]| ...\n", name);
        return 1;
 }
 
@@ -74,14 +76,18 @@ static int parse_options(int argc, char *argv[])
 {
        int c, index = 1;
 
-       while ((c = getopt(argc, argv, "cu")) != -1) {
+       while ((c = getopt(argc, argv, "cug")) != -1) {
                switch (c) {
                case 'c':
                        do_clear = 1;
                        index++;
                        break;
                case 'u':
-                       align_mask = 0;
+                       force_unalign = 1;
+                       index++;
+                       break;
+               case 'g':
+                       splice_flags = SPLICE_F_GIFT;
                        index++;
                        break;
                default:
@@ -95,21 +101,21 @@ static int parse_options(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
        unsigned char *b1, *b2;
-       struct stat sb;
 
        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)) {
-               fprintf(stderr, "stdout must be a pipe\n");
+       if (check_output_pipe())
                return usage(argv[0]);
-       }
 
        b1 = ALIGN(malloc(SPLICE_SIZE + align_mask));
        b2 = ALIGN(malloc(SPLICE_SIZE + align_mask));
 
+       if (force_unalign) {
+               b1 += 1024;
+               b2 += 1024;
+       }
+
        memset(b1, 0xaa, SPLICE_SIZE);
        memset(b2, 0xbb, SPLICE_SIZE);