From b702228c4ea55f3dbb7f493220f7180db6bf1c51 Mon Sep 17 00:00:00 2001 From: Sebastian Hahta <joseha@utu.fi> Date: Thu, 18 Aug 2022 15:47:59 +0300 Subject: [PATCH] workarounds for UWP build --- src/loguru.cpp | 30 ++++++++++++++++++++++++++++++ src/uri.cpp | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/loguru.cpp b/src/loguru.cpp index 4b5fe3d..28771d2 100644 --- a/src/loguru.cpp +++ b/src/loguru.cpp @@ -18,6 +18,36 @@ #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif // __GNUC__ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +#include <stdlib.h> + +// strdup() not available for UWP apps +char* strdup_uwp_workaround_(const char* str_in) { + unsigned int size_inc = 64; + unsigned int size = 32; + unsigned int cnt = 0; + + char* str_out = static_cast<char*>(malloc(size)); + do { + if (cnt == size) { + size += size_inc; + str_out = static_cast<char*>(realloc(str_out, size)); + + size_inc = 2*size_inc; + } + + str_out[cnt] = str_in[cnt]; + + } while (str_in[cnt++] != '\0'); + + return str_out; +} + +#define strdup strdup_uwp_workaround_ + +#endif + + #define LOGURU_REPLACE_GLOG 1 #include <ftl/lib/loguru.hpp> diff --git a/src/uri.cpp b/src/uri.cpp index d28bbba..efa5b6d 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -43,8 +43,8 @@ std::string get_home_dir() { #if defined(WIN32) const char* homeDrive = std::getenv("HOMEDRIVE"); const char* homePath = std::getenv("HOMEPATH"); - return string((homeDrive) ? homeDrive : "") - + string((homePath) ? homePath : ""); + return std::string((homeDrive) ? homeDrive : "") + + std::string((homePath) ? homePath : ""); #else return std::getenv("HOME"); #endif -- GitLab