aboutsummaryrefslogtreecommitdiff
path: root/libxcb/src/xcb_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'libxcb/src/xcb_util.c')
-rw-r--r--libxcb/src/xcb_util.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index fcb11f042..4fc8797c5 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -34,7 +34,9 @@
#include <stddef.h>
#include <unistd.h>
#include <string.h>
+#ifndef _MSC_VER
#include <arpa/inet.h>
+#endif
#ifdef _WIN32
#include "xcb_windefs.h"
@@ -57,6 +59,13 @@
# include <sys/stat.h>
#endif
+#ifdef _MSC_VER
+#ifdef close
+#undef close
+#endif
+#define close(fd) closesocket(fd)
+#endif
+
int xcb_popcount(uint32_t mask)
{
uint32_t y;
@@ -260,7 +269,7 @@ static int _xcb_socket(int family, int type, int proto)
static int _xcb_do_connect(int fd, const struct sockaddr* addr, int addrlen) {
- int on = 1;
+ char on = 1;
if(fd < 0)
return -1;
@@ -271,6 +280,23 @@ static int _xcb_do_connect(int fd, const struct sockaddr* addr, int addrlen) {
return connect(fd, addr, addrlen);
}
+#ifdef WIN32
+int InitWSA(void)
+{
+ static WSADATA wsadata;
+
+ if (!wsadata.wVersion)
+ {
+ ptw32_processInitialize();
+ if (WSAStartup(0x0202, &wsadata))
+ return -1;
+ }
+ return 0;
+}
+#else
+#define InitWSA()
+#endif
+
static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port)
{
int fd = -1;
@@ -310,6 +336,11 @@ static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short
}
#endif
+#ifdef WIN32
+ if (InitWSA()<0)
+ return -1;
+#endif
+
snprintf(service, sizeof(service), "%hu", port);
if(getaddrinfo(host, service, &hints, &results))
/* FIXME: use gai_strerror, and fill in error connection */