Skip to content
Snippets Groups Projects
Commit 6d29c202 authored by bunnei's avatar bunnei
Browse files

Merge pull request #1672 from wwylele/win-driver-fix

Fix driver root identification on Windows
parents 32dfd4b4 43b6cbd7
No related branches found
No related tags found
No related merge requests found
...@@ -69,9 +69,10 @@ static void StripTailDirSlashes(std::string &fname) ...@@ -69,9 +69,10 @@ static void StripTailDirSlashes(std::string &fname)
{ {
if (fname.length() > 1) if (fname.length() > 1)
{ {
size_t i = fname.length() - 1; size_t i = fname.length();
while (fname[i] == DIR_SEP_CHR) while (i > 0 && fname[i - 1] == DIR_SEP_CHR)
fname[i--] = '\0'; --i;
fname.resize(i);
} }
return; return;
} }
...@@ -85,6 +86,10 @@ bool Exists(const std::string &filename) ...@@ -85,6 +86,10 @@ bool Exists(const std::string &filename)
StripTailDirSlashes(copy); StripTailDirSlashes(copy);
#ifdef _WIN32 #ifdef _WIN32
// Windows needs a slash to identify a driver root
if (copy.size() != 0 && copy.back() == ':')
copy += DIR_SEP_CHR;
int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info);
#else #else
int result = stat64(copy.c_str(), &file_info); int result = stat64(copy.c_str(), &file_info);
...@@ -102,6 +107,10 @@ bool IsDirectory(const std::string &filename) ...@@ -102,6 +107,10 @@ bool IsDirectory(const std::string &filename)
StripTailDirSlashes(copy); StripTailDirSlashes(copy);
#ifdef _WIN32 #ifdef _WIN32
// Windows needs a slash to identify a driver root
if (copy.size() != 0 && copy.back() == ':')
copy += DIR_SEP_CHR;
int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info);
#else #else
int result = stat64(copy.c_str(), &file_info); int result = stat64(copy.c_str(), &file_info);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment