diff --git a/httplib.h b/httplib.h index c621f5b..5565e4d 100644 --- a/httplib.h +++ b/httplib.h @@ -2910,9 +2910,12 @@ inline bool mmap::open(const char *path) { #if defined(_WIN32) std::wstring wpath; - for (size_t i = 0; i < strlen(path); i++) { - wpath += path[i]; - } + int unicode_char_len = ::MultiByteToWideChar(CP_UTF8, 0, path, -1, nullptr, 0); + if (unicode_char_len <= 0) return false; + wpath.resize(unicode_char_len + 10); + if (::MultiByteToWideChar(CP_UTF8, 0, path, static_cast(strlen(path)), &wpath[0], + static_cast(wpath.size())) <= 0) + return false; #if _WIN32_WINNT >= _WIN32_WINNT_WIN8 hFile_ = ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ,