@@ -34,24 +34,35 @@ bool InternalGetFullPathName(const StringPiece& file_name, std::string* path,
3434 // "The filename or extension is too long" even if long path supported is
3535 // enabled. GetFullPathNameW() must be used for this function to work!
3636 path->clear ();
37+ // Convert to wide filename first.
3738 std::string filename_str = file_name.AsString ();
38- DWORD full_size = GetFullPathNameA (filename_str.c_str (), 0 , NULL , NULL );
39- if (full_size == 0 ) {
40- *err = " GetFullPathNameA(" + filename_str + " ): " + GetLastErrorString ();
39+ std::wstring wide_filename;
40+ if (!ConvertUTF8ToWin32Unicode (filename_str, &wide_filename, err))
41+ return false ;
42+
43+ // Call GetFullPathNameW()
44+ DWORD wide_full_size = GetFullPathNameW (wide_filename.c_str (), 0 , NULL , NULL );
45+ if (wide_full_size == 0 ) {
46+ *err = " GetFullPathNameW(" +
47+ std::string (wide_filename.begin (), wide_filename.end ()) +
48+ " ): " + GetLastErrorString ();
4149 return false ;
4250 }
4351
44- // NOTE: full_size includes the null-terminating character.
45- path->resize (static_cast <size_t >(full_size - 1 ));
46- DWORD result2 = GetFullPathNameA (filename_str.c_str (), full_size,
47- const_cast <char *>(path->data ()), NULL );
48- if (result2 == 0 ) {
49- *err = " GetFullPathNameA(" + filename_str + " ): " + GetLastErrorString ();
52+ // NOTE: wide_full_size includes the null-terminating character.
53+ std::wstring wide_path;
54+ wide_path.resize (static_cast <size_t >(wide_full_size - 1 ));
55+ DWORD wide_full_size2 =
56+ GetFullPathNameW (wide_filename.c_str (), wide_full_size,
57+ const_cast <wchar_t *>(wide_path.data ()), NULL );
58+ if (wide_full_size2 == 0 ) {
59+ *err = " GetFullPathNameW(" + filename_str + " ): " + GetLastErrorString ();
60+ path->clear ();
5061 return false ;
5162 }
5263
53- path-> resize ( static_cast < size_t >(result2));
54- return true ;
64+ // Convert wide_path to Unicode.
65+ return ConvertWin32UnicodeToUTF8 (wide_path, path, err) ;
5566}
5667
5768// Get the drive prefix of a given filename. On success set |*drive| then return
0 commit comments