static const WCHAR* UNCPathPrefix;
static const WCHAR* UNCExtendedPathPrefix;
static const WCHAR VolumeSeparatorChar;
+ #define UNCPATHPREFIX W("\\\\")
#endif //FEATURE_PAL
static const WCHAR LongFile::DirectorySeparatorChar;
static const WCHAR LongFile::AltDirectorySeparatorChar;
const WCHAR* LongFile::ExtendedPrefix = W("\\\\?\\");
const WCHAR* LongFile::DevicePathPrefix = W("\\\\.\\");
const WCHAR* LongFile::UNCExtendedPathPrefix = W("\\\\?\\UNC\\");
-const WCHAR* LongFile::UNCPathPrefix = W("\\\\");
+const WCHAR* LongFile::UNCPathPrefix = UNCPATHPREFIX;
BOOL LongFile::IsExtended(SString & path)
{
//In this case if path is \\server the extended syntax should be like \\?\UNC\server
//The below logic populates the path from prefixLen offset from the start. This ensures that first 2 characters are overwritten
//
- prefixLen = prefix.GetCount() - 2;
+ prefixLen = prefix.GetCount() - (COUNT_T)wcslen(UNCPATHPREFIX);
+ _ASSERTE(prefixLen > 0 );
}
}
}
+ SString fullpath(SString::Literal,buffer + prefixLen);
- //wcscpy_s always termintes with NULL, so we are saving the character that will be overwriiten
- WCHAR temp = buffer[prefix.GetCount()];
- wcscpy_s(buffer, prefix.GetCount() + 1, prefix.GetUnicode());
- buffer[prefix.GetCount()] = temp;
- path.CloseBuffer(ret + prefixLen);
+ //Check if the resolved path is a UNC. By default we assume relative path to resolve to disk
+ if (fullpath.BeginsWith(UNCPathPrefix) && prefixLen != prefix.GetCount() - (COUNT_T)wcslen(UNCPATHPREFIX))
+ {
+
+ //Remove the leading '\\' from the UNC path to be replaced with UNCExtendedPathPrefix
+ fullpath.Replace(fullpath.Begin(), (COUNT_T)wcslen(UNCPATHPREFIX), UNCExtendedPathPrefix);
+ path.CloseBuffer();
+ path.Set(fullpath);
+ }
+ else
+ {
+ //wcscpy_s always termintes with NULL, so we are saving the character that will be overwriiten
+ WCHAR temp = buffer[prefix.GetCount()];
+ wcscpy_s(buffer, prefix.GetCount() + 1, prefix.GetUnicode());
+ buffer[prefix.GetCount()] = temp;
+ path.CloseBuffer(ret + prefixLen);
+ }
return S_OK;
}