#include <vector>
#include <sstream>
+#include <locale>
+#include <codecvt>
+
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
}
}
+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),
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
// 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);