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..b7154051f6b8107336fb18f32bfd9c66cbb5a64f 100644 |
| --- a/base/file_util_win.cc |
| +++ b/base/file_util_win.cc |
| @@ -10,6 +10,7 @@ |
| #include <shlobj.h> |
| #include <time.h> |
| +#include <algorithm> |
| #include <limits> |
| #include <string> |
| @@ -948,4 +949,26 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) { |
| return success; |
| } |
| +int GetMaximumPathComponentLength(const FilePath& path) { |
| + base::ThreadRestrictions::AssertIOAllowed(); |
| + |
| + wchar_t volume_path[MAX_PATH]; |
| + if (!GetVolumePathNameW(path.NormalizePathSeparators().value().c_str(), |
| + volume_path, |
| + MAX_PATH)) { |
|
Mark Mentovai
2013/02/15 13:49:42
arraysize(volume_path)
kinaba
2013/02/18 03:30:21
Done.
|
| + return -1; |
| + } |
| + |
| + DWORD max_length = 0; |
| + if (!GetVolumeInformationW(volume_path, NULL, 0, NULL, &max_length, NULL, |
| + NULL, 0)) { |
| + return -1; |
| + } |
| + |
| + // path.Append(name).value().size() must be less than MAX_PATH. |
| + size_t prefix = path.StripTrailingSeparators().value().size() + 1; |
| + int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix)); |
|
Mark Mentovai
2013/02/15 13:49:42
So one +1 is for the separator and one -1 is to ke
Mark Mentovai
2013/02/15 13:49:42
You might not be able to get rid of all of the sta
kinaba
2013/02/18 03:30:21
Added some comments for clarification.
kinaba
2013/02/18 03:30:21
The expression assigned to |prefix| has type size_
|
| + return std::min(whole_path_limit, static_cast<int>(max_length)); |
| +} |
| + |
| } // namespace file_util |