From: Simon Tatham Date: Tue, 14 Feb 2017 23:19:13 +0000 (+0000) Subject: Fixes for winelib building (used by our Coverity build). X-Git-Tag: 0.68~21 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=991d30412d0911e7727a852d0a00ae0f1bec1b3e;p=PuTTY.git Fixes for winelib building (used by our Coverity build). Avoided referring to some functions and header files that aren't there in the winelib world (_vsnprintf, _stricmp, SecureZeroMemory, multimon.h), and worked around a really amazingly annoying issue in which Winelib objects to you using the type 'fd_set' unless you included winsock2.h before stdlib.h. --- diff --git a/misc.c b/misc.c index 5fd58a13..391ea1ba 100644 --- a/misc.c +++ b/misc.c @@ -406,7 +406,7 @@ static char *dupvprintf_inner(char *buf, int oldlen, int oldsize, } while (1) { -#if defined _WINDOWS && _MSC_VER < 1900 /* 1900 == VS2015 has real snprintf */ +#if defined _WINDOWS && !defined __WINE__ && _MSC_VER < 1900 /* 1900 == VS2015 has real snprintf */ #define vsnprintf _vsnprintf #endif #ifdef va_copy diff --git a/windows/window.c b/windows/window.c index 2fb12c80..fbbf4ce3 100644 --- a/windows/window.c +++ b/windows/window.c @@ -10,6 +10,10 @@ #include #include +#ifdef __WINE__ +#define NO_MULTIMON /* winelib doesn't have this */ +#endif + #ifndef NO_MULTIMON #define COMPILE_MULTIMON_STUBS #endif diff --git a/windows/winnet.c b/windows/winnet.c index d9da95ce..fb121e3f 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -5,11 +5,15 @@ * unfix.org. */ +#include /* need to put this first, for winelib builds */ + #include #include #include #define DEFINE_PLUG_METHOD_MACROS +#define NEED_DECLARATION_OF_SELECT /* in order to initialise it */ + #include "putty.h" #include "network.h" #include "tree234.h" @@ -236,6 +240,13 @@ int sk_startup(int hi, int lo) return TRUE; } +/* Actually define this function pointer, which won't have been + * defined alongside all the others by PUTTY_DO_GLOBALS because of the + * annoying winelib header-ordering issue. (See comment in winstuff.h.) */ +DECL_WINDOWS_FUNCTION(/* empty */, int, select, + (int, fd_set FAR *, fd_set FAR *, + fd_set FAR *, const struct timeval FAR *)); + void sk_init(void) { #ifndef NO_IPV6 diff --git a/windows/winsftp.c b/windows/winsftp.c index 437ef439..e25d7e06 100644 --- a/windows/winsftp.c +++ b/windows/winsftp.c @@ -2,8 +2,11 @@ * winsftp.c: the Windows-specific parts of PSFTP and PSCP. */ +#include /* need to put this first, for winelib builds */ #include +#define NEED_DECLARATION_OF_SELECT + #include "putty.h" #include "psftp.h" #include "ssh.h" diff --git a/windows/winstuff.h b/windows/winstuff.h index 8c281944..c1918d4a 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -89,14 +89,25 @@ struct FontSpec *fontspec_new(const char *name, #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR)) #define DF_END 0x0001 +#ifdef __WINE__ +#define NO_SECUREZEROMEMORY /* winelib doesn't have this */ +#endif + #ifndef NO_SECUREZEROMEMORY #define PLATFORM_HAS_SMEMCLR /* inhibit cross-platform one in misc.c */ #endif +#ifndef __WINE__ /* Up-to-date Windows headers warn that the unprefixed versions of * these names are deprecated. */ #define stricmp _stricmp #define strnicmp _strnicmp +#else +/* Compiling with winegcc, _neither_ version of these functions + * exists. Use the POSIX names. */ +#define stricmp strcasecmp +#define strnicmp strncasecmp +#endif #define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE /* used in sshshare.c */ @@ -276,12 +287,21 @@ DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect, (SOCKET, HWND, u_int, long)); DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect, (SOCKET, WSAEVENT, long)); -DECL_WINDOWS_FUNCTION(GLOBAL, int, select, - (int, fd_set FAR *, fd_set FAR *, - fd_set FAR *, const struct timeval FAR *)); DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void)); DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents, (SOCKET, WSAEVENT, LPWSANETWORKEVENTS)); +#ifdef NEED_DECLARATION_OF_SELECT +/* This declaration is protected by an ifdef for the sake of building + * against winelib, in which you have to include winsock2.h before + * stdlib.h so that the right fd_set type gets defined. It would be a + * pain to do that throughout this codebase, so instead I arrange that + * only a modules actually needing to use (or define, or initialise) + * this function pointer will see its declaration, and _those_ modules + * - which will be Windows-specific anyway - can take more care. */ +DECL_WINDOWS_FUNCTION(GLOBAL, int, select, + (int, fd_set FAR *, fd_set FAR *, + fd_set FAR *, const struct timeval FAR *)); +#endif extern int socket_writable(SOCKET skt);