From 4e6c1ea648977fceae8200b0bbc7e7c5be876ea6 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 18 Dec 2017 00:06:53 +1100 Subject: [PATCH] [host] fix build in VS++ --- host/Util.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/host/Util.h b/host/Util.h index 3e75ec8e..b006a543 100644 --- a/host/Util.h +++ b/host/Util.h @@ -36,7 +36,14 @@ public: { std::string defaultPath; - const char *libPath = getenv("SystemRoot"); +#if __MINGW32__ + const char * libPath = getenv("SystemRoot"); + const size_t libPathLen = strlen(libPath); +#else + char * libPath; + size_t libPathLen; + _dupenv_s(&libPath, &libPathLen, "SystemRoot"); +#endif if (!libPath) { @@ -44,9 +51,12 @@ public: return defaultPath; } - if (!strlen(libPath)) + if (!libPathLen) { DEBUG_ERROR("The SystemRoot environment variable is not set"); +#ifndef __MINGW32__ + free(libPath); +#endif return defaultPath; } #ifdef _WIN64 @@ -60,6 +70,9 @@ public: { defaultPath = std::string(libPath) + "\\System32"; } +#endif +#ifndef __MINGW32__ + free(libPath); #endif return defaultPath; }