Skip to contentSkip to conversation

qemu-sockets: Fix compiler warning (regression for MinGW)

PATCH Applied Stefan Weil 2 participants 2 messages Sep 28, 2012 – Oct 5, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-sockets: Fix compiler warning (regression for MinGW)

setsockopt needs a type cast for MinGW. That type cast is missing in a recent commit which results in a compiler warning.

Like for other socket related functions which have the same problem, we add a 'qemu_setsockopt' macro which provides that type cast where needed and use the new macro to avoid the warning.

A 'qemu_getsockopt' is also added and can be used for future modifications.

---
 qemu-common.h  |   10 +++++++++-
 qemu-sockets.c |    2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)
qemu-common.h +9 -1
index 4f0ed9e..14c5407 100644
@@ -225,11 +225,19 @@ int qemu_pipe(int pipefd[2]);
 #endif
 
 #ifdef _WIN32
-/* MinGW needs a type cast for the 'buf' argument. */
+/* MinGW needs type casts for the 'buf' and 'optval' arguments. */
+#define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
+    getsockopt(sockfd, level, optname, (void *)optval, optlen)
+#define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
+    setsockopt(sockfd, level, optname, (const void *)optval, optlen)
 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
 #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
     sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen)
 #else
+#define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
+    getsockopt(sockfd, level, optname, optval, optlen)
+#define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
+    setsockopt(sockfd, level, optname, optval, optlen)
 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
 #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
     sendto(sockfd, buf, len, flags, destaddr, addrlen)
qemu-sockets.c +1 -1
index 1f14e8b..0f59490 100644
@@ -282,7 +282,7 @@ static int inet_connect_addr(struct addrinfo *addr, bool *in_progress,
                 inet_strfamily(addr->ai_family), strerror(errno));
         return -1;
     }
-    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+    qemu_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
     if (connect_state != NULL) {
         socket_set_nonblock(sock);
     }
Signature · 1 line
1.7.10
#1 lore raw
Quoted 7 lines · Stefan Weil

setsockopt needs a type cast for MinGW. That type cast is missing in a recent commit which results in a compiler warning.

Like for other socket related functions which have the same problem, we add a 'qemu_setsockopt' macro which provides that type cast where needed and use the new macro to avoid the warning.

Quoted 8 lines

A 'qemu_getsockopt' is also added and can be used for future modifications.

---
 qemu-common.h  |   10 +++++++++-
 qemu-sockets.c |    2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan