Skip to content

Commit f8e797a

Browse files
committed
Use utf-8 to decode filename
1 parent 2fc1148 commit f8e797a

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

util/env_win.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,16 @@ class Win32Env : public Env
203203

204204
void ToWidePath(const std::string& value, std::wstring& target) {
205205
wchar_t buffer[MAX_PATH];
206-
MultiByteToWideChar(CP_ACP, 0, value.c_str(), -1, buffer, MAX_PATH);
206+
MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, buffer, MAX_PATH);
207207
target = buffer;
208208
}
209209

210210
void ToNarrowPath(const std::wstring& value, std::string& target) {
211211
char buffer[MAX_PATH];
212-
WideCharToMultiByte(CP_ACP, 0, value.c_str(), -1, buffer, MAX_PATH, NULL, NULL);
212+
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, buffer, MAX_PATH, NULL, NULL);
213213
target = buffer;
214214
}
215215

216-
std::string GetCurrentDir()
217-
{
218-
CHAR path[MAX_PATH];
219-
::GetModuleFileNameA(::GetModuleHandleA(NULL),path,MAX_PATH);
220-
*strrchr(path,'\\') = 0;
221-
return std::string(path);
222-
}
223-
224216
std::wstring GetCurrentDirW()
225217
{
226218
WCHAR path[MAX_PATH];
@@ -229,6 +221,13 @@ std::wstring GetCurrentDirW()
229221
return std::wstring(path);
230222
}
231223

224+
std::string GetCurrentDir()
225+
{
226+
std::string path;
227+
ToNarrowPath(GetCurrentDirW(), path);
228+
return path;
229+
}
230+
232231
std::string& ModifyPath(std::string& path)
233232
{
234233
if(path[0] == '/' || path[0] == '\\'){

0 commit comments

Comments
 (0)