diff --git a/net/sock.c b/net/sock.c index 33e8367..75f7e82 100644 --- a/net/sock.c +++ b/net/sock.c @@ -50,13 +50,14 @@ #define EWOULDBLOCK WSAEWOULDBLOCK #define EALREADY WSAEALREADY #define socklen_t int +#ifndef __MINGW32__ #define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list)) #endif +#endif #include "sock.h" #include "resolver.h" - /* sock_initialize ** ** initializes the socket library. you must call this @@ -160,7 +161,8 @@ int sock_valid_socket(sock_t sock) socklen_t optlen; optlen = sizeof(int); - ret = getsockopt(sock, SOL_SOCKET, SO_TYPE, &optval, &optlen); + /* apparently on windows getsockopt.optval is a char * */ + ret = getsockopt(sock, SOL_SOCKET, SO_TYPE, (void*) &optval, &optlen); return (ret == 0); } @@ -193,7 +195,11 @@ int inet_aton(const char *s, struct in_addr *a) int sock_set_blocking(sock_t sock, const int block) { #ifdef _WIN32 +#ifdef __MINGW32__ + u_long varblock = block; +#else int varblock = block; +#endif #endif if ((!sock_valid_socket(sock)) || (block < 0) || (block > 1)) @@ -433,10 +439,14 @@ int sock_connected (int sock, unsigned timeout) switch (select(sock + 1, NULL, &wfds, NULL, &tv)) { - case 0: return SOCK_TIMEOUT; - default: if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &val, &size) < 0) - val = SOCK_ERROR; - case -1: return val; + case 0: + return SOCK_TIMEOUT; + default: + /* on windows getsockopt.val is defined as char* */ + if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) < 0) + val = SOCK_ERROR; + case -1: + return val; } } diff --git a/net/sock.h b/net/sock.h index dcf6288..6151f11 100644 --- a/net/sock.h +++ b/net/sock.h @@ -24,11 +24,14 @@ #include -#ifdef _WIN32 +#ifdef HAVE_WINSOCK2_H #include -#include -#else +#endif + +#ifdef HAVE_UNISTD_H #include +#elif _WIN32 +#include #endif #ifdef HAVE_SYS_UIO_H diff --git a/timing/timing.c b/timing/timing.c index 556c405..5b6737e 100644 --- a/timing/timing.c +++ b/timing/timing.c @@ -24,6 +24,10 @@ #include #endif +#ifdef __MINGW32__ +#include +#endif + #include "timing.h" /* see timing.h for an explanation of _mangle() */ @@ -34,7 +38,14 @@ uint64_t timing_get_time(void) { #ifdef _WIN32 +#ifdef __MINGW32__ + struct timeb t; + + ftime(&t); + return t.time * 1000 + t.millitm) +#else return timeGetTime(); +#endif #else struct timeval mtv;