Diff between 25a471a83e02e1effb15d5a488b3f0085eaeb675 and afb47b13c600b0c5e01b4fe3f2e670e89faa6ec2

Changed Files

File Additions Deletions Status
profiles/input/device.c +10 -8 modified

Full Patch

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 4310dd1..6c64ff1 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -20,6 +20,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
+#include <sys/uio.h>
 
 #include "lib/bluetooth.h"
 #include "lib/hidp.h"
@@ -162,32 +163,33 @@ static bool hidp_send_message(GIOChannel *chan, uint8_t hdr,
 {
 	int fd;
 	ssize_t len;
-	uint8_t msg[size + 1];
+	struct iovec iov[2];
 
 	if (!chan) {
 		error("BT socket not connected");
 		return false;
 	}
 
+	iov[0].iov_base = &hdr;
+	iov[0].iov_len = sizeof(hdr);
+
 	if (data == NULL)
 		size = 0;
 
-	msg[0] = hdr;
-	if (size > 0)
-		memcpy(&msg[1], data, size);
-	++size;
+	iov[1].iov_base = (void *)data;
+	iov[1].iov_len = size;
 
 	fd = g_io_channel_unix_get_fd(chan);
 
-	len = write(fd, msg, size);
+	len = writev(fd, iov, 2);
 	if (len < 0) {
 		error("BT socket write error: %s (%d)", strerror(errno), errno);
 		return false;
 	}
 
-	if ((size_t) len < size) {
+	if ((size_t) len < size + 1) {
 		error("BT socket write error: partial write (%zd of %zu bytes)",
-								len, size);
+								len, size + 1);
 		return false;
 	}