]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Fixes for winelib building (used by our Coverity build).
authorSimon Tatham <anakin@pobox.com>
Tue, 14 Feb 2017 23:19:13 +0000 (23:19 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 14 Feb 2017 23:25:26 +0000 (23:25 +0000)
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.

misc.c
windows/window.c
windows/winnet.c
windows/winsftp.c
windows/winstuff.h

diff --git a/misc.c b/misc.c
index 5fd58a131550d7f0bd9c5429b9ab4339f8f461d1..391ea1ba06eb86b7ecefa6e5a598a4447635e600 100644 (file)
--- 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
index 2fb12c80dd1453271e334681e50069d961548e85..fbbf4ce3f32c25547948f5a8207d81697e83531b 100644 (file)
 #include <limits.h>
 #include <assert.h>
 
+#ifdef __WINE__
+#define NO_MULTIMON                    /* winelib doesn't have this */
+#endif
+
 #ifndef NO_MULTIMON
 #define COMPILE_MULTIMON_STUBS
 #endif
index d9da95ce59570f3665120000c7a9155233d720aa..fb121e3f7ea681a9cf2645a5aa063c4a91429bdb 100644 (file)
@@ -5,11 +5,15 @@
  * unfix.org.
  */
 
+#include <winsock2.h> /* need to put this first, for winelib builds */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
 
 #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
index 437ef439d0c23651cb2f7bee8ad8be79350b1359..e25d7e064ee33efdaf1bae9dc64aee52db9a3638 100644 (file)
@@ -2,8 +2,11 @@
  * winsftp.c: the Windows-specific parts of PSFTP and PSCP.
  */
 
+#include <winsock2.h> /* need to put this first, for winelib builds */
 #include <assert.h>
 
+#define NEED_DECLARATION_OF_SELECT
+
 #include "putty.h"
 #include "psftp.h"
 #include "ssh.h"
index 8c281944534350b0496cfd65e17dfc4bc3d308ed..c1918d4ad2744273786a45d8079c2f7129859292 100644 (file)
@@ -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);