Chromium Code Reviews| Index: tools/clang/plugins/ChromeClassTester.cpp |
| diff --git a/tools/clang/plugins/ChromeClassTester.cpp b/tools/clang/plugins/ChromeClassTester.cpp |
| index cd508068e111399c0319dbebc49e707bd94fcea4..89dba6167462ff8a7de0e2683f2abedd6716a3ab 100644 |
| --- a/tools/clang/plugins/ChromeClassTester.cpp |
| +++ b/tools/clang/plugins/ChromeClassTester.cpp |
| @@ -16,6 +16,9 @@ |
| #ifdef LLVM_ON_UNIX |
| #include <sys/param.h> |
| #endif |
| +#if defined(LLVM_ON_WIN32) |
| +#include <windows.h> |
| +#endif |
| using namespace clang; |
| using chrome_checker::Options; |
| @@ -119,27 +122,42 @@ bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { |
| #if defined(LLVM_ON_UNIX) |
| // Resolve the symlinktastic relative path and make it absolute. |
| - char resolvedPath[MAXPATHLEN]; |
| if (options_.no_realpath) { |
| // Same reason as windows below, but we don't need to do |
| // the '\\' manipulation on linux. |
| filename.insert(filename.begin(), '/'); |
| } else if (realpath(filename.c_str(), resolvedPath)) { |
| + char resolvedPath[MAXPATHLEN]; |
| filename = resolvedPath; |
| } |
| #endif |
| #if defined(LLVM_ON_WIN32) |
| - std::replace(filename.begin(), filename.end(), '\\', '/'); |
| + // Make path absolute. |
| + if (options_.no_realpath) { |
| + // This turns e.g. "gen/dir/file.cc" to "/gen/dir/file.cc" which lets the |
| + // "/gen/" banned_dir work. |
| + filename.insert(filename.begin(), '/'); |
| + } else { |
| + // The Windows dance: Convert to UTF-16, call GetFullPathNameW, convert back |
| + DWORD size_needed = |
| + MultiByteToWideChar(CP_UTF8, 0, filename.data(), -1, nullptr, 0); |
| + std::wstring utf16(size_needed, 0); |
|
dcheng
2016/09/09 18:57:29
Nit: '\0' maybe, for slightly better clarity?
Nico
2016/09/09 19:06:33
meh, it's overwritten below anyways. And wouldn't
dcheng
2016/09/09 19:09:48
I think '\0' should work fine here: the L prefix i
|
| + MultiByteToWideChar(CP_UTF8, 0, filename.data(), -1, |
| + &utf16[0], size_needed); |
| + |
| + size_needed = GetFullPathName(utf16.data(), 0, nullptr, nullptr) + 1; // nul |
|
dcheng
2016/09/09 18:57:29
Nit: let's be consistent about calling the W versi
dcheng
2016/09/09 18:57:29
Also:
If the lpBuffer buffer is too small to cont
Nico
2016/09/09 19:06:33
Oh oops, done, thanks!
Nico
2016/09/09 19:06:33
You're right, I misread the docs. Done.
|
| + std::wstring full_utf16(size_needed, 0); |
| + GetFullPathNameW(utf16.data(), full_utf16.size(), &full_utf16[0], nullptr); |
| + |
| + size_needed = WideCharToMultiByte(CP_UTF8, 0, full_utf16.data(), -1, |
| + nullptr, 0, nullptr, nullptr); |
| + filename.resize(size_needed); |
| + WideCharToMultiByte(CP_UTF8, 0, full_utf16.data(), -1, &filename[0], |
| + size_needed, nullptr, nullptr); |
| + } |
| - // On Posix, realpath() has made the path absolute. On Windows, this isn't |
| - // necessarily true, so prepend a '/' to the path to make sure the |
| - // banned_directories_ loop below works correctly. |
| - // This turns e.g. "gen/dir/file.cc" to "/gen/dir/file.cc" which lets the |
| - // "/gen/" banned_dir work. |
| - // This seems simpler than converting to utf16, calling GetFullPathNameW(), |
| - // and converting back to utf8. |
| - filename.insert(filename.begin(), '/'); |
| + std::replace(filename.begin(), filename.end(), '\\', '/'); |
| #endif |
| for (const std::string& allowed_dir : allowed_directories_) { |