From 42bf85d10b9f77b9fc6853fb29420087d1989cf8 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 13 Jun 2017 06:31:25 +0300 Subject: [PATCH] Fixes for MSVC. --- src/Options.cpp | 31 +++++++++++++++++++------------ src/Summary.cpp | 4 +++- src/net/Network_win.cpp | 18 +++++++++++++----- src/version.h | 16 ++++++++++++++++ 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/Options.cpp b/src/Options.cpp index 9ba9acf7f..c38f417bb 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -25,12 +25,14 @@ #include #include + #ifdef _MSC_VER -#include "getopt/getopt.h" +# include "getopt/getopt.h" #else -#include +# include #endif + #include "Console.h" #include "Cpu.h" #include "donate.h" @@ -391,24 +393,29 @@ void Options::showUsage(int status) const void Options::showVersion() { - /* printf(APP_NAME " " APP_VERSION "\n built on " __DATE__) + printf(APP_NAME " " APP_VERSION "\n built on " __DATE__ - #ifdef __GNUC__ +# if defined(__GNUC__) " with GCC"); printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); - #endif +# elif defined(_MSC_VER) + " with MSVC"); + printf(" %d", MSVC_VERSION); +# else + ); +# endif printf("\n features:" - #ifdef __i386__ +# if defined(__i386__) || defined(_M_IX86) " i386" - #endif - #ifdef __x86_64__ +# elif defined(__x86_64__) || defined(_M_AMD64) " x86_64" - #endif - #ifdef __AES__ +# endif + +# if defined(__AES__) || defined(_MSC_VER) " AES-NI" - #endif - "\n");*/ +# endif + "\n"); printf("\nlibuv/%s\n", uv_version_string()); printf("libjansson/%s\n", JANSSON_VERSION); diff --git a/src/Summary.cpp b/src/Summary.cpp index 7d5f920f4..8c7d3ea31 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -37,8 +37,10 @@ static void print_versions() { char buf[16]; -# ifdef __GNUC__ +# if defined(__GNUC__) snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +# elif defined(_MSC_VER) + snprintf(buf, 16, " MSVC/%d", MSVC_VERSION); # else buf[0] = '\0'; # endif diff --git a/src/net/Network_win.cpp b/src/net/Network_win.cpp index 432ea71ee..15b358b57 100644 --- a/src/net/Network_win.cpp +++ b/src/net/Network_win.cpp @@ -22,7 +22,7 @@ */ -#include +#include #include @@ -51,13 +51,21 @@ static inline OSVERSIONINFOEX winOsVersion() char *Network::userAgent() { const auto osver = winOsVersion(); + const size_t max = 128; - char *buf = static_cast(malloc(128)); + char *buf = static_cast(malloc(max)); + int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion); + +# if defined(__x86_64__) || defined(_M_AMD64) + length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s", uv_version_string()); +# else + length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string()); +# endif # ifdef __GNUC__ - snprintf(buf, 128, "%s/%s (Windows NT %lu.%lu; Win64; x64) libuv/%s gcc/%d.%d.%d", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion, uv_version_string(), __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# else - snprintf(buf, 128, "%s/%s (Windows NT %lu.%lu; Win64; x64) libuv/%s", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion, uv_version_string()); + length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +#elif _MSC_VER + length += snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION); # endif return buf; diff --git a/src/version.h b/src/version.h index d7bde178a..326b65672 100644 --- a/src/version.h +++ b/src/version.h @@ -37,4 +37,20 @@ #define APP_VER_BUILD 0 #define APP_VER_REV 0 +#ifdef _MSC_VER +# if _MSC_VER == 1910 +# define MSVC_VERSION 2017 +# elif _MSC_VER == 1900 +# define MSVC_VERSION 2015 +# elif _MSC_VER == 1800 +# define MSVC_VERSION 2013 +# elif _MSC_VER == 1700 +# define MSVC_VERSION 2012 +# elif _MSC_VER == 1600 +# define MSVC_VERSION 2010 +# else +# define MSVC_VERSION 0 +# endif +#endif + #endif /* __VERSION_H__ */