tools: Use sendfile() instead of mmap() for AF_ALG test utility
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 8 Jun 2011 05:43:05 +0000 (07:43 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 8 Jun 2011 05:43:05 +0000 (07:43 +0200)
tools/alg-test.c

index e10e11d..33c3975 100644 (file)
 #include <unistd.h>
 #include <string.h>
 #include <sys/stat.h>
-#include <sys/mman.h>
+#include <sys/sendfile.h>
 #include <sys/socket.h>
 #include <linux/if_alg.h>
 
-static void build_hash(int sk, char *map, size_t size, const char *pathname)
+static void build_hash(int sk, int fd, size_t size, const char *pathname)
 {
        unsigned char hash[20];
        ssize_t written, length;
        int i;
 
-       written = send(sk, map, size, 0);
+       written = sendfile(sk, fd, NULL, size);
        if (written < 0)
                perror("Failed to write data");
 
@@ -58,7 +58,6 @@ static void build_hash(int sk, char *map, size_t size, const char *pathname)
 static int create_hash(int sk, const char *pathname)
 {
        struct stat st;
-       char *map;
        int fd;
 
        fd = open(pathname, O_RDONLY);
@@ -70,15 +69,7 @@ static int create_hash(int sk, const char *pathname)
                return -1;
        }
 
-       map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
-       if (map == NULL || map == MAP_FAILED) {
-               close(fd);
-               return -1;
-       }
-
-       build_hash(sk, map, st.st_size, pathname);
-
-       munmap(map, st.st_size);
+       build_hash(sk, fd, st.st_size, pathname);
 
        close(fd);