summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2011-06-08 07:43:05 +0200
committerMarcel Holtmann <marcel@holtmann.org>2011-06-08 07:43:05 +0200
commitdaae038bc6618c9170ce7abb18faf0c753eeb77a (patch)
tree40028146bdb53ce4c5922c232d53fe9c1ea187fd
parent113894a7cd81d1b8a2456aa51afd3982e99648b4 (diff)
downloadconnman-daae038bc6618c9170ce7abb18faf0c753eeb77a.tar.gz
connman-daae038bc6618c9170ce7abb18faf0c753eeb77a.tar.bz2
connman-daae038bc6618c9170ce7abb18faf0c753eeb77a.zip
tools: Use sendfile() instead of mmap() for AF_ALG test utility
-rw-r--r--tools/alg-test.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/tools/alg-test.c b/tools/alg-test.c
index e10e11d5..33c39756 100644
--- a/tools/alg-test.c
+++ b/tools/alg-test.c
@@ -28,17 +28,17 @@
#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);