From cdb437c54540d2d98edd7e16416733f0973a4c06 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Tue, 28 Nov 2017 20:45:51 -0500 Subject: [PATCH] Fix compilation with VS2017 The primary issue is that in MSVC 14.00 (VS2015) Microsoft added snprintf as a function to the standard library and prevents users from defining it to something else (typically, this was _snprintf). So, only define it when using _MSC_VER < 1900. Other changes are: - Fix macro definition of dup2 - Add macro for getpid - Add function definition for win32_dup - Add missing EXTERNs Signed-off-by: Tim Crawford --- include/iscsi.h | 4 ++-- lib/init.c | 1 + lib/socket.c | 2 +- win32/win32_compat.h | 15 +++++++++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/iscsi.h b/include/iscsi.h index 9b2b85e..798703c 100644 --- a/include/iscsi.h +++ b/include/iscsi.h @@ -166,7 +166,7 @@ enum iscsi_immediate_data { ISCSI_IMMEDIATE_DATA_NO = 0, ISCSI_IMMEDIATE_DATA_YES = 1 }; -int iscsi_set_immediate_data(struct iscsi_context *iscsi, enum iscsi_immediate_data immediate_data); +EXTERN int iscsi_set_immediate_data(struct iscsi_context *iscsi, enum iscsi_immediate_data immediate_data); /* * This function is used to set the desired mode for initial_r2t @@ -179,7 +179,7 @@ enum iscsi_initial_r2t { ISCSI_INITIAL_R2T_NO = 0, ISCSI_INITIAL_R2T_YES = 1 }; -int +EXTERN int iscsi_set_initial_r2t(struct iscsi_context *iscsi, enum iscsi_initial_r2t initial_r2t); diff --git a/lib/init.c b/lib/init.c index 645b05f..88bc7eb 100644 --- a/lib/init.c +++ b/lib/init.c @@ -22,6 +22,7 @@ #define _GNU_SOURCE #if defined(WIN32) +#include "win32/win32_compat.h" #else #include #include diff --git a/lib/socket.c b/lib/socket.c index a7c2fa0..22e6e57 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -1102,7 +1102,7 @@ void iscsi_set_bind_interfaces(struct iscsi_context *iscsi, char * interfaces _U #endif } -#ifdef WIN32 +#if defined(_MSC_VER) && _MSC_VER < 1900 static iscsi_transport iscsi_transport_tcp = { iscsi_tcp_connect, iscsi_tcp_queue_pdu, diff --git a/win32/win32_compat.h b/win32/win32_compat.h index 62330f6..8ec388a 100644 --- a/win32/win32_compat.h +++ b/win32/win32_compat.h @@ -22,9 +22,10 @@ THE SOFTWARE. */ /*Adaptions by memphiz@xbmc.org*/ -#ifdef WIN32 #ifndef win32_COMPAT_H_ #define win32_COMPAT_H_ + +#ifdef WIN32 #define NO_IPv6 1 #include @@ -65,16 +66,22 @@ typedef int socklen_t; #define writev win32_writev #define strncasecmp _strnicmp #define strdup _strdup -#define dup2(x, y, z) win32_dup2(x, y) +#define dup2(x, y) win32_dup2(x, y) #define poll(x, y, z) win32_poll(x, y, z) #define inet_pton(x,y,z) win32_inet_pton(x,y,z) #define sleep(x) Sleep(x * 1000) +#define getpid GetCurrentProcessId + +#if defined(_MSC_VER) && _MSC_VER < 1900 #define snprintf(a, b, c, ...) _snprintf_s(a, b, b, c, ## __VA_ARGS__) +#endif + int win32_inet_pton(int af, const char * src, void * dst); int win32_poll(struct pollfd *fds, unsigned int nfsd, int timeout); int win32_gettimeofday(struct timeval *tv, struct timezone *tz); ssize_t win32_writev(int fd, const struct iovec *iov, int iovcnt); ssize_t win32_readv(int fd, const struct iovec *iov, int iovcnt); +int win32_dup2(int oldfd, int newfd); struct iovec { void *iov_base; @@ -83,5 +90,5 @@ struct iovec { #define inline -#endif//win32_COMPAT_H_ -#endif//WIN32 +#endif // WIN32 +#endif // win32_COMPAT_H_