From a504f02fa8cbf771c26c74272a53ae6dc69c9c8a Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Thu, 4 Apr 2019 14:01:49 +0900 Subject: [PATCH] remove dependency from multiByteToWideChar multiByteToWideChar() removed from unix exports from coreclr 3.0.0 prev 3 So, add char* to char16_t* API and use that --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 21 ++++++++++++--------- NativeLauncher/launcher/dotnet/dotnet_launcher.h | 1 - 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 2f946c9..1464d9b 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -23,6 +23,9 @@ #include #include +#include +#include + #include #include #include @@ -221,13 +224,19 @@ static void initEnvForSpecialFolder() } } +static std::u16string utf8ToUtf16(char* str) +{ + std::wstring_convert, char16_t> convert; + return convert.from_bytes(str); +} + + CoreRuntime::CoreRuntime(const char* mode) : initializeClr(nullptr), executeAssembly(nullptr), shutdown(nullptr), createDelegate(nullptr), setEnvironmentVariable(nullptr), - multiByteToWideChar(nullptr), __coreclrLib(nullptr), __hostHandle(nullptr), __domainId(-1), @@ -348,7 +357,6 @@ int CoreRuntime::initialize(bool standalone) CORELIB_RETURN_IF_NOSYM(coreclr_shutdown_ptr, shutdown, "coreclr_shutdown"); CORELIB_RETURN_IF_NOSYM(coreclr_create_delegate_ptr, createDelegate, "coreclr_create_delegate"); CORELIB_RETURN_IF_NOSYM(set_environment_variable_ptr, setEnvironmentVariable, "SetEnvironmentVariableW"); - CORELIB_RETURN_IF_NOSYM(multi_byte_to_wide_char_ptr, multiByteToWideChar, "MultiByteToWideChar"); #undef CORELIB_RETURN_IF_NOSYM @@ -491,15 +499,10 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i // application data path can be changed by owner. So, we have to set data path just before launching. char* localDataPath = app_get_data_path(); if (localDataPath != nullptr) { - char16_t envval[PATH_MAX] = {0}; - int copied = multiByteToWideChar(0 /* CP_ACP */, 0, localDataPath, -1, envval, PATH_MAX); - if (copied >= PATH_MAX) { - _ERR("Data Path is bigger than PATH_MAX"); - } + std::u16string envval = utf8ToUtf16(localDataPath); - if (!setEnvironmentVariable(u"XDG_DATA_HOME", envval)) { + if (!setEnvironmentVariable(u"XDG_DATA_HOME", envval.c_str())) { _ERR("Failed to set XDG_DATA_HOME"); - } free(localDataPath); diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index a00b32e..62b1859 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -41,7 +41,6 @@ class CoreRuntime coreclr_shutdown_ptr shutdown; coreclr_create_delegate_ptr createDelegate; set_environment_variable_ptr setEnvironmentVariable; - multi_byte_to_wide_char_ptr multiByteToWideChar; std::string __nativeLibDirectory; void* __coreclrLib; void* __hostHandle; -- 2.7.4