@@ -203,24 +203,16 @@ class Win32Env : public Env
203
203
204
204
void ToWidePath (const std::string& value, std::wstring& target) {
205
205
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);
207
207
target = buffer;
208
208
}
209
209
210
210
void ToNarrowPath (const std::wstring& value, std::string& target) {
211
211
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 );
213
213
target = buffer;
214
214
}
215
215
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
-
224
216
std::wstring GetCurrentDirW ()
225
217
{
226
218
WCHAR path[MAX_PATH];
@@ -229,6 +221,13 @@ std::wstring GetCurrentDirW()
229
221
return std::wstring (path);
230
222
}
231
223
224
+ std::string GetCurrentDir ()
225
+ {
226
+ std::string path;
227
+ ToNarrowPath (GetCurrentDirW (), path);
228
+ return path;
229
+ }
230
+
232
231
std::string& ModifyPath (std::string& path)
233
232
{
234
233
if (path[0 ] == ' /' || path[0 ] == ' \\ ' ){
@@ -764,14 +763,16 @@ uint64_t Win32Env::NowMicros()
764
763
static Status CreateDirInner ( const std::string& dirname )
765
764
{
766
765
Status sRet ;
767
- DWORD attr = ::GetFileAttributes (dirname.c_str ());
766
+ std::wstring dirnameW;
767
+ ToWidePath (dirname, dirnameW);
768
+ DWORD attr = ::GetFileAttributesW (dirnameW.c_str ());
768
769
if (attr == INVALID_FILE_ATTRIBUTES) { // doesn't exist:
769
770
std::size_t slash = dirname.find_last_of (" \\ " );
770
771
if (slash != std::string::npos){
771
772
sRet = CreateDirInner (dirname.substr (0 , slash));
772
773
if (!sRet .ok ()) return sRet ;
773
774
}
774
- BOOL result = ::CreateDirectory (dirname .c_str (), NULL );
775
+ BOOL result = ::CreateDirectoryW (dirnameW .c_str (), NULL );
775
776
if (result == FALSE ) {
776
777
sRet = Status::IOError (dirname, " Could not create directory." );
777
778
return sRet ;
0 commit comments