Chromium Code Reviews| Index: base/file_util_win.cc |
| diff --git a/base/file_util_win.cc b/base/file_util_win.cc |
| index 65fd6ebb43c3ff09bd82790678cfe2ac06ad50c7..42d8b5bbecbdd7c7735a2624ad1b700e5031b40f 100644 |
| --- a/base/file_util_win.cc |
| +++ b/base/file_util_win.cc |
| @@ -8,8 +8,10 @@ |
| #include <psapi.h> |
| #include <shellapi.h> |
| #include <shlobj.h> |
| +#include <shlwapi.h> |
| #include <time.h> |
| +#include <algorithm> |
| #include <limits> |
| #include <string> |
| @@ -948,4 +950,29 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) { |
| return success; |
| } |
| +int GetMaximumPathComponentLength(const FilePath& path) { |
| + base::ThreadRestrictions::AssertIOAllowed(); |
| + FilePath full_path(path); |
| + if (!full_path.IsAbsolute() && !file_util::AbsolutePath(&full_path)) |
| + return -1; |
| + |
| + // GetVolumeInformationW takes a root path ended with a backslash. |
| + std::vector<FilePath::CharType> root(full_path.value().begin(), |
| + full_path.value().end()); |
| + root.resize(root.size() + 2); // +2 for trailing \0 and backslash. |
| + PathStripToRootW(&root[0]); |
|
Mark Mentovai
2013/02/14 13:40:58
Looking at http://msdn.microsoft.com/en-us/library
asanka
2013/02/14 16:06:53
Unfortunately PathCchStripToRoot() appears to be o
|
| + PathAddBackslashW(&root[0]); |
|
Mark Mentovai
2013/02/14 13:40:58
Same with PathCchAddBackslash. See http://msdn.mic
|
| + |
| + DWORD max_length = 0; |
| + if (!GetVolumeInformationW(&root[0], NULL, 0, NULL, &max_length, NULL, NULL, |
| + 0)) { |
| + return -1; |
| + } |
| + |
| + // path.Append(name) cannot exceed MAX_PATH. |
| + int whole_path_limit = |
| + std::max(0, MAX_PATH - static_cast<int>(path.value().size()) - 1); |
| + return std::min(whole_path_limit, static_cast<int>(max_length)); |
| +} |
| + |
| } // namespace file_util |