@@ -203,24 +203,16 @@ class Win32Env : public Env
203203
204204void 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
210210void 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-
224216std::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+
232231std::string& ModifyPath (std::string& path)
233232{
234233 if (path[0 ] == ' /' || path[0 ] == ' \\ ' ){
@@ -764,14 +763,16 @@ uint64_t Win32Env::NowMicros()
764763static Status CreateDirInner ( const std::string& dirname )
765764{
766765 Status sRet ;
767- DWORD attr = ::GetFileAttributes (dirname.c_str ());
766+ std::wstring dirnameW;
767+ ToWidePath (dirname, dirnameW);
768+ DWORD attr = ::GetFileAttributesW (dirnameW.c_str ());
768769 if (attr == INVALID_FILE_ATTRIBUTES) { // doesn't exist:
769770 std::size_t slash = dirname.find_last_of (" \\ " );
770771 if (slash != std::string::npos){
771772 sRet = CreateDirInner (dirname.substr (0 , slash));
772773 if (!sRet .ok ()) return sRet ;
773774 }
774- BOOL result = ::CreateDirectory (dirname .c_str (), NULL );
775+ BOOL result = ::CreateDirectoryW (dirnameW .c_str (), NULL );
775776 if (result == FALSE ) {
776777 sRet = Status::IOError (dirname, " Could not create directory." );
777778 return sRet ;
0 commit comments