Fix build on Windows
Notable changes: Protect include of unistd.h (and other POSIX headers). Use SOCKET (which is larger than int) and closesocket (because close is not compatible) for sockets. Use <stdint.h>'s intptr_t instead of the non-portable ssize_t. Signed-off-by: Peter Harris <pharris@opentext.com>
This commit is contained in:
parent
cd0fba98a2
commit
4b0d9d3868
|
@ -51,7 +51,11 @@ extern "C" {
|
|||
* @file xcb.h
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define XCB_PACKED __attribute__((__packed__))
|
||||
#else
|
||||
#define XCB_PACKED
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup XCB_Core_API XCB Core API
|
||||
|
|
|
@ -31,8 +31,6 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <X11/Xauth.h>
|
||||
#include <sys/param.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
@ -49,6 +47,8 @@
|
|||
#endif
|
||||
#include "xcb_windefs.h"
|
||||
#else
|
||||
#include <sys/param.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
@ -271,10 +271,17 @@ static int compute_auth(xcb_auth_info_t *info, Xauth *authptr, struct sockaddr *
|
|||
to the value returned by either getpeername() or getsockname()
|
||||
(according to POSIX, applications should not assume a particular
|
||||
length for `sockaddr_un.sun_path') */
|
||||
#ifdef _WIN32
|
||||
static struct sockaddr *get_peer_sock_name(int(_stdcall *socket_func)(SOCKET,
|
||||
struct sockaddr *,
|
||||
socklen_t *),
|
||||
int fd)
|
||||
#else
|
||||
static struct sockaddr *get_peer_sock_name(int (*socket_func)(int,
|
||||
struct sockaddr *,
|
||||
socklen_t *),
|
||||
int fd)
|
||||
#endif
|
||||
{
|
||||
socklen_t socknamelen = sizeof(struct sockaddr) + INITIAL_SOCKNAME_SLACK;
|
||||
socklen_t actual_socknamelen = socknamelen;
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
@ -48,7 +47,9 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include "xcb_windefs.h"
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif /* _WIN32 */
|
||||
|
@ -345,7 +346,11 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
|
|||
|
||||
c = calloc(1, sizeof(xcb_connection_t));
|
||||
if(!c) {
|
||||
#ifdef _WIN32
|
||||
closesocket(fd);
|
||||
#else
|
||||
close(fd);
|
||||
#endif
|
||||
return _xcb_conn_ret_error(XCB_CONN_CLOSED_MEM_INSUFFICIENT) ;
|
||||
}
|
||||
|
||||
|
@ -378,7 +383,11 @@ void xcb_disconnect(xcb_connection_t *c)
|
|||
|
||||
/* disallow further sends and receives */
|
||||
shutdown(c->fd, SHUT_RDWR);
|
||||
#ifdef _WIN32
|
||||
closesocket(c->fd);
|
||||
#else
|
||||
close(c->fd);
|
||||
#endif
|
||||
|
||||
pthread_mutex_destroy(&c->iolock);
|
||||
_xcb_in_destroy(&c->in);
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -40,6 +39,7 @@
|
|||
#include <poll.h>
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
@ -365,7 +365,7 @@ static void free_reply_list(struct reply_list *head)
|
|||
}
|
||||
}
|
||||
|
||||
static int read_block(const int fd, void *buf, const ssize_t len)
|
||||
static int read_block(const int fd, void *buf, const intptr_t len)
|
||||
{
|
||||
int done = 0;
|
||||
while(done < len)
|
||||
|
|
|
@ -31,7 +31,11 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#include "xcb.h"
|
||||
|
|
|
@ -36,12 +36,12 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "xcb_windefs.h"
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
@ -415,7 +415,11 @@ static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short
|
|||
if(_xcb_do_connect(fd, (struct sockaddr*)&_s, sizeof(_s)) >= 0)
|
||||
break;
|
||||
|
||||
#ifdef _WIN32
|
||||
closesocket(fd);
|
||||
#else
|
||||
close(fd);
|
||||
#endif
|
||||
fd = -1;
|
||||
++_c;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue