Patchwork [v6,1/4] sockets: introduce set_socket_error()

login
register
mail settings
Submitter Amos Kong
Date March 27, 2012, 2:56 p.m.
Message ID <47ec5537-6df7-4471-b4d7-851de8777ca8@zmail13.collab.prod.int.phx2.redhat.com>
Download mbox | patch
Permalink /patch/148963/
State New
Headers show

Comments

Amos Kong - March 27, 2012, 2:56 p.m.
Introduce set_socket_error() to set the errno, use
WSASetLastError() for win32.
Sometimes, clean work would rewrite errno in error path,
we can use this function to restore real errno.

Changes from V5:
- create a function to set errno
    
Signed-off-by: Amos Kong <akong@redhat.com>

Patch

diff --git a/qemu-sockets.c b/qemu-sockets.c
index 6bcb8e3..f822187 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -56,6 +56,11 @@  static QemuOptsList dummy_opts = {
     },
 };
 
+void set_errno(int e)
+{
+       errno = e;
+}
+
 static int inet_getport(struct addrinfo *e)
 {
     struct sockaddr_in *i4;
diff --git a/qemu_socket.h b/qemu_socket.h
index fe4cf6c..62c1921 100644
--- a/qemu_socket.h
+++ b/qemu_socket.h
@@ -8,6 +8,7 @@ 
 #include <ws2tcpip.h>
 
 #define socket_error() WSAGetLastError()
+#define set_socket_error(e) WSASetLastError(e)
 #undef EINTR
 #define EWOULDBLOCK WSAEWOULDBLOCK
 #define EINTR       WSAEINTR
@@ -25,7 +26,10 @@  int inet_aton(const char *cp, struct in_addr *ia);
 #include <netdb.h>
 #include <sys/un.h>
 
+void set_errno(int e);
+
 #define socket_error() errno
+#define set_socket_error(e) set_errno(e)
 #define closesocket(s) close(s)
 
 #endif /* !_WIN32 */