From fe10226cc94d64baef4ef4038356d9ca40470dc5 Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Sun, 18 Apr 2021 21:23:25 +0200 Subject: [PATCH] Fix building with Visual Studio 2008 This older Microsoft compiler does not support mixing declarations and code and misses some error defines. This commit enables building with VS2008 by moving up some variable declarations and defining error codes to their WinSock counterparts in case they're not defined. Signed-off-by: Christian Beier --- client/client_shared.c | 3 ++- config.h | 9 +++++++++ include/mosquitto.h | 2 +- lib/misc_mosq.c | 6 ++++-- lib/net_mosq.h | 3 +++ lib/time_mosq.c | 2 ++ src/conf.c | 9 +++++---- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/client/client_shared.c b/client/client_shared.c index 97ee5660..c668c9f4 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -756,8 +756,9 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c tmp = strchr(url, '@'); if(tmp) { + char *colon; *tmp++ = 0; - char *colon = strchr(url, ':'); + colon = strchr(url, ':'); if(colon) { *colon = 0; cfg->password = strdup(colon + 1); diff --git a/config.h b/config.h index bdce7469..9f614f8c 100644 --- a/config.h +++ b/config.h @@ -33,6 +33,15 @@ #if defined(_MSC_VER) && _MSC_VER < 1900 # define snprintf sprintf_s # define EPROTO ECONNABORTED +# ifndef ECONNABORTED +# define ECONNABORTED WSAECONNABORTED +# endif +# ifndef ENOTCONN +# define ENOTCONN WSAENOTCONN +# endif +# ifndef ECONNREFUSED +# define ECONNREFUSED WSAECONNREFUSED +# endif #endif #ifdef WIN32 diff --git a/include/mosquitto.h b/include/mosquitto.h index e7e09d70..9822b934 100644 --- a/include/mosquitto.h +++ b/include/mosquitto.h @@ -49,7 +49,7 @@ extern "C" { # define libmosq_EXPORT #endif -#if defined(_MSC_VER) && _MSC_VER < 1900 +#if defined(_MSC_VER) && _MSC_VER < 1900 && !defined(bool) # ifndef __cplusplus # define bool char # define true 1 diff --git a/lib/misc_mosq.c b/lib/misc_mosq.c index 8f2f2d2a..b2118c46 100644 --- a/lib/misc_mosq.c +++ b/lib/misc_mosq.c @@ -57,6 +57,8 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) DWORD ulen = UNLEN; SECURITY_DESCRIPTOR sd; DWORD dwCreationDisposition; + int fd; + FILE *fptr; switch(mode[0]){ case 'a': @@ -97,12 +99,12 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) LocalFree(pacl); - int fd = _open_osfhandle((intptr_t)hfile, 0); + fd = _open_osfhandle((intptr_t)hfile, 0); if (fd < 0) { return NULL; } - FILE *fptr = _fdopen(fd, mode); + fptr = _fdopen(fd, mode); if (!fptr) { _close(fd); return NULL; diff --git a/lib/net_mosq.h b/lib/net_mosq.h index 30342179..9feae613 100644 --- a/lib/net_mosq.h +++ b/lib/net_mosq.h @@ -36,6 +36,9 @@ typedef SSIZE_T ssize_t; # define COMPAT_ECONNRESET WSAECONNRESET # define COMPAT_EINTR WSAEINTR # define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK +# ifndef EINPROGRESS +# define EINPROGRESS WSAEINPROGRESS +# endif #else # define COMPAT_CLOSE(a) close(a) # define COMPAT_ECONNRESET ECONNRESET diff --git a/lib/time_mosq.c b/lib/time_mosq.c index e8eb0755..da4a9154 100644 --- a/lib/time_mosq.c +++ b/lib/time_mosq.c @@ -24,7 +24,9 @@ Contributors: #endif #ifdef WIN32 +#if !(defined(_MSC_VER) && _MSC_VER <= 1500) # define _WIN32_WINNT _WIN32_WINNT_VISTA +#endif # include #else # include diff --git a/src/conf.c b/src/conf.c index bc4158ae..ae867732 100644 --- a/src/conf.c +++ b/src/conf.c @@ -2028,15 +2028,16 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, #endif }else if(!strcmp(token, "topic")){ #ifdef WITH_BRIDGE + char *topic = NULL; + enum mosquitto__bridge_direction direction = bd_out; + uint8_t qos = 0; + char *local_prefix = NULL, *remote_prefix = NULL; + if(reload) continue; /* FIXME */ if(!cur_bridge){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration."); return MOSQ_ERR_INVAL; } - char *topic = NULL; - enum mosquitto__bridge_direction direction = bd_out; - uint8_t qos = 0; - char *local_prefix = NULL, *remote_prefix = NULL; token = strtok_r(NULL, " ", &saveptr); if(token){