aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/cpp/util')
-rw-r--r--src/main/cpp/util/file_platform.h3
-rw-r--r--src/main/cpp/util/file_windows.cc13
2 files changed, 10 insertions, 6 deletions
diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h
index 7733e7a5c5..50b75de3bb 100644
--- a/src/main/cpp/util/file_platform.h
+++ b/src/main/cpp/util/file_platform.h
@@ -205,7 +205,8 @@ void ForEachDirectoryEntry(const std::string &path,
#if defined(COMPILER_MSVC) || defined(__CYGWIN__)
// Like `AsWindowsPath` but the result is absolute and has UNC prefix if needed.
-bool AsWindowsPathWithUncPrefix(const std::string &path, std::wstring *wpath);
+bool AsWindowsPathWithUncPrefix(const std::string &path, std::wstring *wpath,
+ size_t max_path = 260 /* MAX_PATH */);
// Same as `AsWindowsPath`, but returns a lowercase 8dot3 style shortened path.
// Result will never have a UNC prefix, nor a trailing "/" or "\".
diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc
index f763f9ef48..5159917eb4 100644
--- a/src/main/cpp/util/file_windows.cc
+++ b/src/main/cpp/util/file_windows.cc
@@ -101,8 +101,8 @@ static bool HasDriveSpecifierPrefix(const char_type* ch) {
return CharTraits<char_type>::IsAlpha(ch[0]) && ch[1] == ':';
}
-static void AddUncPrefixMaybe(wstring* path) {
- if (path->size() >= MAX_PATH && !HasUncPrefix(path->c_str())) {
+static void AddUncPrefixMaybe(wstring* path, size_t max_path = MAX_PATH) {
+ if (path->size() >= max_path && !HasUncPrefix(path->c_str())) {
*path = wstring(L"\\\\?\\") + *path;
}
}
@@ -483,7 +483,8 @@ bool AsWindowsPath(const string& path, wstring* result) {
return true;
}
-bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath) {
+bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath,
+ size_t max_path) {
if (IsDevNull(path)) {
wpath->assign(L"NUL");
return true;
@@ -497,7 +498,7 @@ bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath) {
if (!IsAbsolute(path)) {
wpath->assign(wstring(GetCwdW().get()) + L"\\" + *wpath);
}
- AddUncPrefixMaybe(wpath);
+ AddUncPrefixMaybe(wpath, max_path);
return true;
}
@@ -1120,7 +1121,9 @@ bool MakeDirectories(const string& path, unsigned int mode) {
return false;
}
wstring wpath;
- if (!AsWindowsPathWithUncPrefix(path, &wpath)) {
+ // According to MSDN, CreateDirectory's limit without the UNC prefix is
+ // 248 characters (so it could fit another filename before reaching MAX_PATH).
+ if (!AsWindowsPathWithUncPrefix(path, &wpath, 248)) {
return false;
}
return MakeDirectoriesW(wpath);