remove dependency from multiByteToWideChar
authorWoongsuk Cho <ws77.cho@samsung.com>
Thu, 4 Apr 2019 05:01:49 +0000 (14:01 +0900)
committerWoongsuk Cho <ws77.cho@samsung.com>
Thu, 4 Apr 2019 06:58:32 +0000 (15:58 +0900)
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
NativeLauncher/launcher/dotnet/dotnet_launcher.h

index 2f946c9..1464d9b 100644 (file)
@@ -23,6 +23,9 @@
 #include <vector>
 #include <sstream>
 
+#include <locale>
+#include <codecvt>
+
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -221,13 +224,19 @@ static void initEnvForSpecialFolder()
        }
 }
 
+static std::u16string utf8ToUtf16(char* str)
+{
+       std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, 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);
index a00b32e..62b1859 100644 (file)
@@ -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;