diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d2c66e71..74c920c13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,8 @@ endif() if(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_X86_") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_X86_ -D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN") endif() # Include files diff --git a/libfreerdp-core/CMakeLists.txt b/libfreerdp-core/CMakeLists.txt index f187614bf..604d95331 100644 --- a/libfreerdp-core/CMakeLists.txt +++ b/libfreerdp-core/CMakeLists.txt @@ -90,7 +90,12 @@ set(LIBFREERDP_CORE_SRCS add_library(freerdp-core SHARED ${LIBFREERDP_CORE_SRCS}) -target_link_libraries(freerdp-core ${ZLIB_LIBRARIES}) +if(WIN32) + target_link_libraries(freerdp-core ws2_32) +else() + target_link_libraries(freerdp-core ${ZLIB_LIBRARIES}) +endif() + target_link_libraries(freerdp-core ${OPENSSL_LIBRARIES}) target_link_libraries(freerdp-core freerdp-utils) diff --git a/libfreerdp-core/registry.c b/libfreerdp-core/registry.c index 62104dcc0..67b174066 100644 --- a/libfreerdp-core/registry.c +++ b/libfreerdp-core/registry.c @@ -19,6 +19,8 @@ #include "registry.h" +#include + static char registry_dir[] = "freerdp"; static char registry_file[] = "config.txt"; @@ -142,7 +144,11 @@ void registry_init(rdpRegistry* registry) if (stat(registry->path, &stat_info) != 0) { +#ifndef _WIN32 mkdir(registry->path, S_IRUSR | S_IWUSR | S_IXUSR); +#else + CreateDirectory(registry->path, 0); +#endif printf("creating directory %s\n", registry->path); } diff --git a/libfreerdp-core/tcp.c b/libfreerdp-core/tcp.c index 4fc1752f5..a0c6200ee 100644 --- a/libfreerdp-core/tcp.c +++ b/libfreerdp-core/tcp.c @@ -28,9 +28,12 @@ #ifndef _WIN32 #include #include +#include #include #include -#include +#else +#define socklen_t int +#define close(_fd) closesocket(_fd) #endif #include @@ -195,6 +198,7 @@ boolean tcp_disconnect(rdpTcp * tcp) boolean tcp_set_blocking_mode(rdpTcp* tcp, boolean blocking) { +#ifndef _WIN32 int flags; flags = fcntl(tcp->sockfd, F_GETFL); @@ -205,15 +209,15 @@ boolean tcp_set_blocking_mode(rdpTcp* tcp, boolean blocking) } if (blocking == True) - { - /* blocking */ fcntl(tcp->sockfd, F_SETFL, flags & ~(O_NONBLOCK)); - } else - { - /* non-blocking */ fcntl(tcp->sockfd, F_SETFL, flags | O_NONBLOCK); - } +#else + u_long arg = blocking; + ioctlsocket(tcp->sockfd, FIONBIO, &arg); + tcp->wsa_event = WSACreateEvent(); + WSAEventSelect(tcp->sockfd, tcp->wsa_event, FD_READ); +#endif return True; } diff --git a/libfreerdp-core/tcp.h b/libfreerdp-core/tcp.h index 046bb73e5..dec673dbf 100644 --- a/libfreerdp-core/tcp.h +++ b/libfreerdp-core/tcp.h @@ -21,6 +21,11 @@ #ifndef __TCP_H #define __TCP_H +#ifdef _WIN32 +#include +#include +#endif + #include #include #include @@ -29,7 +34,6 @@ #define MSG_NOSIGNAL 0 #endif - typedef struct rdp_tcp rdpTcp; typedef boolean (*TcpConnect) (rdpTcp* tcp, const char* hostname, uint16 port); typedef boolean (*TcpDisconnect) (rdpTcp* tcp); @@ -44,6 +48,9 @@ struct rdp_tcp TcpConnect connect; TcpDisconnect disconnect; TcpSetBlockingMode set_blocking_mode; +#ifdef _WIN32 + WSAEVENT wsa_event; +#endif }; boolean tcp_connect(rdpTcp* tcp, const char* hostname, uint16 port); diff --git a/libfreerdp-utils/sleep.c b/libfreerdp-utils/sleep.c index 8fd004e08..fb4277dfa 100644 --- a/libfreerdp-utils/sleep.c +++ b/libfreerdp-utils/sleep.c @@ -19,12 +19,31 @@ #include -#define _XOPEN_SOURCE 500 - #include + +#ifndef _WIN32 +#define _XOPEN_SOURCE 500 #include +#else +#include +#endif void freerdp_usleep(uint32 useconds) { +#ifndef _WIN32 usleep(useconds); +#else + uint64 t1; + uint64 t2; + uint64 freq; + + QueryPerformanceCounter((LARGE_INTEGER*) &t1); + QueryPerformanceCounter((LARGE_INTEGER*) &freq); + + do + { + QueryPerformanceCounter((LARGE_INTEGER*) &t2); + } + while((t2 - t1) < useconds); +#endif } diff --git a/libfreerdp-utils/thread.c b/libfreerdp-utils/thread.c index cfa43284c..3f95df1a8 100644 --- a/libfreerdp-utils/thread.c +++ b/libfreerdp-utils/thread.c @@ -21,6 +21,11 @@ #include #include #include + +#ifdef _WIN32 +#include +#endif + #include #include #include diff --git a/libfreerdp-utils/wait_obj.c b/libfreerdp-utils/wait_obj.c index 190192d16..34273380b 100644 --- a/libfreerdp-utils/wait_obj.c +++ b/libfreerdp-utils/wait_obj.c @@ -27,7 +27,7 @@ #ifndef _WIN32 #include #else -#include +#include #endif #ifdef HAVE_UNISTD_H