summaryrefslogtreecommitdiff
path: root/src/utilcode/util.cpp
diff options
context:
space:
mode:
authorRama Krishnan Raghupathy <ramarag@microsoft.com>2016-02-18 18:21:18 -0800
committerRama Krishnan Raghupathy <ramarag@microsoft.com>2016-02-19 18:09:11 -0800
commitf98fb85e72d0f24c58d9e54b8b3bff2c67f985fb (patch)
treea532e7803fbbe420807eb7d9390108554b02c46d /src/utilcode/util.cpp
parent01ffa08a2e4748e9826956ea961eacb227b6ee87 (diff)
downloadcoreclr-f98fb85e72d0f24c58d9e54b8b3bff2c67f985fb.tar.gz
coreclr-f98fb85e72d0f24c58d9e54b8b3bff2c67f985fb.tar.bz2
coreclr-f98fb85e72d0f24c58d9e54b8b3bff2c67f985fb.zip
This Change Adds initial Support for LongFiles in the VM,
They are: 1. Wrappers for OS APIs which take or return PATHS 2. Fixing the usage of following Api's: GetEnvironmentVariableW SearchPathW GetShortPathNameW GetLongPathNameW GetModuleFileName Work remaining: Remove fixed size buffers in the VM
Diffstat (limited to 'src/utilcode/util.cpp')
-rw-r--r--src/utilcode/util.cpp89
1 files changed, 5 insertions, 84 deletions
diff --git a/src/utilcode/util.cpp b/src/utilcode/util.cpp
index 6c5378e5d9..dcc6b83e21 100644
--- a/src/utilcode/util.cpp
+++ b/src/utilcode/util.cpp
@@ -3238,6 +3238,8 @@ FileLockHolder::~FileLockHolder()
void FileLockHolder::Acquire(LPCWSTR lockName, HANDLE hInterrupt, BOOL* pInterrupted)
{
+ WRAPPER_NO_CONTRACT;
+
DWORD dwErr = 0;
DWORD dwAccessDeniedRetry = 0;
const DWORD MAX_ACCESS_DENIED_RETRIES = 10;
@@ -3557,53 +3559,7 @@ BOOL IsClrHostedLegacyComObject(REFCLSID rclsid)
}
#endif // FEATURE_COMINTEROP
-// Returns the directory for HMODULE. So, if HMODULE was for "C:\Dir1\Dir2\Filename.DLL",
-// then this would return "C:\Dir1\Dir2\" (note the trailing backslash).
-HRESULT GetHModuleDirectory(
- __in HMODULE hMod,
- __out_z __out_ecount(cchPath) LPWSTR wszPath,
- size_t cchPath)
-{
- CONTRACTL
- {
- NOTHROW;
- GC_NOTRIGGER;
- CANNOT_TAKE_LOCK;
- }
- CONTRACTL_END;
-
- DWORD dwRet = WszGetModuleFileName(hMod, wszPath, static_cast<DWORD>(cchPath));
- if (dwRet == cchPath)
- { // If there are cchPath characters in the string, it means that the string
- // itself is longer than cchPath and GetModuleFileName had to truncate at cchPath.
- return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
- }
- else if (dwRet == 0)
- { // Some other error.
- return HRESULT_FROM_GetLastError();
- }
-
- LPWSTR wszEnd = wcsrchr(wszPath, W('\\'));
- if (wszEnd == NULL)
- { // There was no backslash? Not sure what's going on.
- return E_UNEXPECTED;
- }
-
- // Include the backslash in the resulting string.
- *(++wszEnd) = W('\0');
-
- return S_OK;
-}
-
-SString & GetHModuleDirectory(HMODULE hMod, SString &ssDir)
-{
- LPWSTR wzDir = ssDir.OpenUnicodeBuffer(_MAX_PATH);
- HRESULT hr = GetHModuleDirectory(hMod, wzDir, _MAX_PATH);
- ssDir.CloseBuffer(FAILED(hr) ? 0 : static_cast<COUNT_T>(wcslen(wzDir)));
- IfFailThrow(hr);
- return ssDir;
-}
#if !defined(FEATURE_CORECLR) && !defined(SELF_NO_HOST) && !defined(FEATURE_UTILCODE_NO_DEPENDENCIES)
@@ -3936,39 +3892,14 @@ namespace Win32
// Try to use what the SString already has allocated. If it does not have anything allocated
// or it has < 20 characters allocated, then bump the size requested to _MAX_PATH.
- DWORD dwSize = (DWORD)(ssFileName.GetUnicodeAllocation()) + 1;
- dwSize = (dwSize < 20) ? (_MAX_PATH) : (dwSize);
- DWORD dwResult = WszGetModuleFileName(hModule, ssFileName.OpenUnicodeBuffer(dwSize - 1), dwSize);
+
+ DWORD dwResult = WszGetModuleFileName(hModule, ssFileName);
- // if there was a failure, dwResult == 0;
- // if there was insufficient buffer, dwResult == dwSize;
- // if there was sufficient buffer and a successful write, dwResult < dwSize
- ssFileName.CloseBuffer(dwResult < dwSize ? dwResult : 0);
if (dwResult == 0)
ThrowHR(HRESULT_FROM_GetLastError());
- // Ok, we didn't have enough buffer. Let's loop, doubling the buffer each time, until we succeed.
- while (dwResult == dwSize)
- {
- dwSize = dwSize * 2;
- dwResult = WszGetModuleFileName(hModule, ssFileName.OpenUnicodeBuffer(dwSize - 1), dwSize);
- ssFileName.CloseBuffer(dwResult < dwSize ? dwResult : 0);
-
- if (dwResult == 0)
- ThrowHR(HRESULT_FROM_GetLastError());
- }
-
- // Most of the runtime is not able to handle long filenames. fAllowLongFileNames
- // has a default value of false, so that callers will not accidentally get long
- // file names returned.
- if (!fAllowLongFileNames && ssFileName.BeginsWith(SL(LONG_FILENAME_PREFIX_W)))
- {
- ssFileName.Clear();
- ThrowHR(E_UNEXPECTED);
- }
-
- _ASSERTE(dwResult != 0 && dwResult < dwSize);
+ _ASSERTE(dwResult != 0 );
}
// Returns heap-allocated string in *pwszFileName
@@ -4030,16 +3961,6 @@ namespace Win32
if (!(dwLengthWritten < dwLengthRequired))
ThrowHR(E_UNEXPECTED);
- // Most of the runtime is not able to handle long filenames. fAllowLongFileNames
- // has a default value of false, so that callers will not accidentally get long
- // file names returned.
- if (!fAllowLongFileNames && ssFileName.BeginsWith(SL(LONG_FILENAME_PREFIX_W)))
- {
- ssPathName.Clear();
- if (pdwFilePartIdx != NULL)
- *pdwFilePartIdx = 0;
- ThrowHR(E_UNEXPECTED);
- }
}
} // namespace Win32