Skip to content

Commit 2f9418d

Browse files
authored
Remove some unnecessary path manipulation helpers (#77301)
1 parent 77331bb commit 2f9418d

File tree

4 files changed

+15
-289
lines changed

4 files changed

+15
-289
lines changed

src/coreclr/inc/utilcode.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -958,25 +958,6 @@ void SplitPathInterior(
958958
_Out_opt_ LPCWSTR *pwszExt, _Out_opt_ size_t *pcchExt);
959959

960960

961-
void MakePath(_Out_ CQuickWSTR &path,
962-
_In_ LPCWSTR drive,
963-
_In_ LPCWSTR dir,
964-
_In_ LPCWSTR fname,
965-
_In_ LPCWSTR ext);
966-
967-
WCHAR * FullPath(_Out_writes_ (maxlen) WCHAR *UserBuf, const WCHAR *path, size_t maxlen);
968-
969-
//*****************************************************************************
970-
//
971-
// SString version of the path functions.
972-
//
973-
//*****************************************************************************
974-
void SplitPath(_In_ SString const &path,
975-
__inout_opt SString *drive,
976-
__inout_opt SString *dir,
977-
__inout_opt SString *fname,
978-
__inout_opt SString *ext);
979-
980961
#include "ostype.h"
981962

982963
#define CLRGetTickCount64() GetTickCount64()
@@ -4433,13 +4414,6 @@ inline T* InterlockedCompareExchangeT(
44334414
// Returns the directory for clr module. So, if path was for "C:\Dir1\Dir2\Filename.DLL",
44344415
// then this would return "C:\Dir1\Dir2\" (note the trailing backslash).
44354416
HRESULT GetClrModuleDirectory(SString& wszPath);
4436-
HRESULT CopySystemDirectory(const SString& pPathString, SString& pbuffer);
4437-
4438-
HMODULE LoadLocalizedResourceDLLForSDK(_In_z_ LPCWSTR wzResourceDllName, _In_opt_z_ LPCWSTR modulePath=NULL, bool trySelf=true);
4439-
// This is a slight variation that can be used for anything else
4440-
typedef void* (__cdecl *LocalizedFileHandler)(LPCWSTR);
4441-
void* FindLocalizedFile(_In_z_ LPCWSTR wzResourceDllName, LocalizedFileHandler lfh, _In_opt_z_ LPCWSTR modulePath=NULL);
4442-
44434417

44444418
namespace Clr { namespace Util
44454419
{

src/coreclr/md/enc/stgio.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,14 @@ HRESULT StgIO::Open( // Return code.
312312
m_fFlags = fFlags;
313313
if ((szName != NULL) && (*szName != 0))
314314
{
315-
WCHAR rcExt[_MAX_PATH];
316-
SplitPath(szName, NULL, 0, NULL, 0, NULL, 0, rcExt, _MAX_PATH);
317-
if (SString::_wcsicmp(rcExt, W(".obj")) == 0)
315+
LPCWSTR ext;
316+
size_t extSize;
317+
SplitPathInterior(szName, NULL, 0, NULL, 0, NULL, 0, &ext, &extSize);
318+
if (SString::_wcsicmp(ext, W(".obj")) == 0)
318319
{
319320
m_FileType = FILETYPE_NTOBJ;
320321
}
321-
else if (SString::_wcsicmp(rcExt, W(".tlb")) == 0)
322+
else if (SString::_wcsicmp(ext, W(".tlb")) == 0)
322323
{
323324
m_FileType = FILETYPE_TLB;
324325
}

src/coreclr/utilcode/makepath.cpp

Lines changed: 3 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -10,147 +10,9 @@
1010
*
1111
*******************************************************************************/
1212
#include "stdafx.h"
13-
#include "winwrap.h"
1413
#include "utilcode.h"
1514
#include "ex.h"
1615

17-
18-
/***
19-
*void Makepath() - build path name from components
20-
*
21-
*Purpose:
22-
* create a path name from its individual components
23-
*
24-
*Entry:
25-
* CQuickWSTR &szPath - Buffer for constructed path
26-
* WCHAR *drive - pointer to drive component, may or may not contain
27-
* trailing ':'
28-
* WCHAR *dir - pointer to subdirectory component, may or may not include
29-
* leading and/or trailing '/' or '\' characters
30-
* WCHAR *fname - pointer to file base name component
31-
* WCHAR *ext - pointer to extension component, may or may not contain
32-
* a leading '.'.
33-
*
34-
*Exit:
35-
* path - pointer to constructed path name
36-
*
37-
*Exceptions:
38-
*
39-
*******************************************************************************/
40-
41-
void MakePath (
42-
_Out_ CQuickWSTR &szPath,
43-
_In_ LPCWSTR drive,
44-
_In_ LPCWSTR dir,
45-
_In_ LPCWSTR fname,
46-
_In_ LPCWSTR ext
47-
)
48-
{
49-
CONTRACTL
50-
{
51-
NOTHROW;
52-
GC_NOTRIGGER;
53-
}
54-
CONTRACTL_END
55-
56-
SIZE_T maxCount = 4 // Possible separators between components, plus null terminator
57-
+ (drive != nullptr ? 2 : 0)
58-
+ (dir != nullptr ? wcslen(dir) : 0)
59-
+ (fname != nullptr ? wcslen(fname) : 0)
60-
+ (ext != nullptr ? wcslen(ext) : 0);
61-
LPWSTR path = szPath.AllocNoThrow(maxCount);
62-
63-
const WCHAR *p;
64-
DWORD count = 0;
65-
66-
/* we assume that the arguments are in the following form (although we
67-
* do not diagnose invalid arguments or illegal filenames (such as
68-
* names longer than 8.3 or with illegal characters in them)
69-
*
70-
* drive:
71-
* A ; or
72-
* A:
73-
* dir:
74-
* \top\next\last\ ; or
75-
* /top/next/last/ ; or
76-
* either of the above forms with either/both the leading
77-
* and trailing / or \ removed. Mixed use of '/' and '\' is
78-
* also tolerated
79-
* fname:
80-
* any valid file name
81-
* ext:
82-
* any valid extension (none if empty or null )
83-
*/
84-
85-
/* copy drive */
86-
87-
if (drive && *drive) {
88-
*path++ = *drive;
89-
*path++ = _T(':');
90-
count += 2;
91-
}
92-
93-
/* copy dir */
94-
95-
if ((p = dir)) {
96-
while (*p) {
97-
*path++ = *p++;
98-
count++;
99-
100-
_ASSERTE(count < maxCount);
101-
}
102-
103-
// suppress warning for the following line; this is safe but would require significant code
104-
// delta for prefast to understand.
105-
#ifdef _PREFAST_
106-
#pragma warning( suppress: 26001 )
107-
#endif
108-
if (*(p-1) != _T('/') && *(p-1) != _T('\\')) {
109-
*path++ = _T('\\');
110-
count++;
111-
112-
_ASSERTE(count < maxCount);
113-
}
114-
}
115-
116-
/* copy fname */
117-
118-
if ((p = fname)) {
119-
while (*p) {
120-
*path++ = *p++;
121-
count++;
122-
123-
_ASSERTE(count < maxCount);
124-
}
125-
}
126-
127-
/* copy ext, including 0-terminator - check to see if a '.' needs
128-
* to be inserted.
129-
*/
130-
131-
if ((p = ext)) {
132-
if (*p && *p != _T('.')) {
133-
*path++ = _T('.');
134-
count++;
135-
136-
_ASSERTE(count < maxCount);
137-
}
138-
139-
while ((*path++ = *p++)) {
140-
count++;
141-
142-
_ASSERTE(count < maxCount);
143-
}
144-
}
145-
else {
146-
/* better add the 0-terminator */
147-
*path = _T('\0');
148-
}
149-
150-
szPath.Shrink(count + 1);
151-
}
152-
153-
15416
// Returns the directory for clr module. So, if path was for "C:\Dir1\Dir2\Filename.DLL",
15517
// then this would return "C:\Dir1\Dir2\" (note the trailing backslash).HRESULT GetClrModuleDirectory(SString& wszPath)
15618
HRESULT GetClrModuleDirectory(SString& wszPath)
@@ -170,36 +32,14 @@ HRESULT GetClrModuleDirectory(SString& wszPath)
17032
return HRESULT_FROM_GetLastError();
17133
}
17234

173-
CopySystemDirectory(wszPath, wszPath);
174-
return S_OK;
175-
}
176-
177-
//
178-
// Returns path name from a file name.
179-
// Example: For input "C:\Windows\System.dll" returns "C:\Windows\".
180-
// Warning: The input file name string might be destroyed.
181-
//
182-
// Arguments:
183-
// pPathString - [in] SString with file name
184-
//
185-
// pBuffer - [out] SString .
186-
//
187-
// Return Value:
188-
// S_OK - Output buffer contains path name.
189-
// other errors - If Sstring throws.
190-
//
191-
HRESULT CopySystemDirectory(const SString& pPathString,
192-
SString& pbuffer)
193-
{
19435
HRESULT hr = S_OK;
19536
EX_TRY
19637
{
197-
pbuffer.Set(pPathString);
198-
SString::Iterator iter = pbuffer.End();
199-
if (pbuffer.FindBack(iter,DIRECTORY_SEPARATOR_CHAR_W))
38+
SString::Iterator iter = wszPath.End();
39+
if (wszPath.FindBack(iter,DIRECTORY_SEPARATOR_CHAR_W))
20040
{
20141
iter++;
202-
pbuffer.Truncate(iter);
42+
wszPath.Truncate(iter);
20343
}
20444
else
20545
{

src/coreclr/utilcode/splitpath.cpp

Lines changed: 7 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@
1313
#include "stdafx.h"
1414
#include "winwrap.h"
1515
#include "utilcode.h"
16-
#include "sstring.h"
17-
1816

1917
/***
20-
*SplitPath() - split a path name into its individual components
18+
*SplitPathInterior()
2119
*
2220
*Purpose:
23-
* to split a path name into its individual components
21+
* Split a path name into its individual components
22+
* Just points to each section of the string.
2423
*
2524
*Entry:
2625
* path - pointer to path name to be parsed
27-
* drive - pointer to buffer for drive component, if any
28-
* dir - pointer to buffer for subdirectory component, if any
29-
* fname - pointer to buffer for file base name component, if any
30-
* ext - pointer to buffer for file name extension component, if any
26+
* drive - pointer to set to drive component, if any
27+
* dir - pointer to set to subdirectory component, if any
28+
* fname - pointer to set to file base name component, if any
29+
* ext - pointer to set to file name extension component, if any
3130
*
3231
*Exit:
3332
* drive - pointer to drive string. Includes ':' if a drive was given.
@@ -39,41 +38,6 @@
3938
*Exceptions:
4039
*
4140
*******************************************************************************/
42-
43-
void SplitPath(
44-
const WCHAR *path,
45-
__inout_z __inout_ecount_opt(driveSizeInWords) WCHAR *drive, int driveSizeInWords,
46-
__inout_z __inout_ecount_opt(dirSizeInWords) WCHAR *dir, int dirSizeInWords,
47-
__inout_z __inout_ecount_opt(fnameSizeInWords) WCHAR *fname, size_t fnameSizeInWords,
48-
__inout_z __inout_ecount_opt(extSizeInWords) WCHAR *ext, size_t extSizeInWords)
49-
{
50-
WRAPPER_NO_CONTRACT;
51-
52-
LPCWSTR _wszDrive, _wszDir, _wszFileName, _wszExt;
53-
size_t _cchDrive, _cchDir, _cchFileName, _cchExt;
54-
55-
SplitPathInterior(path,
56-
&_wszDrive, &_cchDrive,
57-
&_wszDir, &_cchDir,
58-
&_wszFileName, &_cchFileName,
59-
&_wszExt, &_cchExt);
60-
61-
if (drive && _wszDrive)
62-
wcsncpy_s(drive, driveSizeInWords, _wszDrive, min(_cchDrive, _MAX_DRIVE));
63-
64-
if (dir && _wszDir)
65-
wcsncpy_s(dir, dirSizeInWords, _wszDir, min(_cchDir, _MAX_DIR));
66-
67-
if (fname && _wszFileName)
68-
wcsncpy_s(fname, fnameSizeInWords, _wszFileName, min(_cchFileName, _MAX_FNAME));
69-
70-
if (ext && _wszExt)
71-
wcsncpy_s(ext, extSizeInWords, _wszExt, min(_cchExt, _MAX_EXT));
72-
}
73-
74-
//*******************************************************************************
75-
// A much more sensible version that just points to each section of the string.
76-
//*******************************************************************************
7741
void SplitPathInterior(
7842
_In_ LPCWSTR wszPath,
7943
_Out_opt_ LPCWSTR *pwszDrive, _Out_opt_ size_t *pcchDrive,
@@ -203,56 +167,3 @@ void SplitPathInterior(
203167
}
204168
}
205169
}
206-
207-
/***
208-
*SplitPath() - split a path name into its individual components
209-
*
210-
*Purpose:
211-
* to split a path name into its individual components
212-
*
213-
*Entry:
214-
* path - SString representing the path name to be parsed
215-
* drive - Out SString for drive component
216-
* dir - Out SString for subdirectory component
217-
* fname - Out SString for file base name component
218-
* ext - Out SString for file name extension component
219-
*
220-
*Exit:
221-
* drive - Drive string. Includes ':' if a drive was given.
222-
* dir - Subdirectory string. Includes leading and trailing
223-
* '/' or '\', if any.
224-
* fname - File base name
225-
* ext - File extension, if any. Includes leading '.'.
226-
*
227-
*Exceptions:
228-
*
229-
*******************************************************************************/
230-
231-
void SplitPath(_In_ SString const &path,
232-
__inout_opt SString *drive,
233-
__inout_opt SString *dir,
234-
__inout_opt SString *fname,
235-
__inout_opt SString *ext)
236-
{
237-
LPCWSTR wzDrive, wzDir, wzFname, wzExt;
238-
size_t cchDrive, cchDir, cchFname, cchExt;
239-
240-
SplitPathInterior(path,
241-
&wzDrive, &cchDrive,
242-
&wzDir, &cchDir,
243-
&wzFname, &cchFname,
244-
&wzExt, &cchExt);
245-
246-
if (drive != NULL)
247-
drive->Set(wzDrive, (COUNT_T)cchDrive);
248-
249-
if (dir != NULL)
250-
dir->Set(wzDir, (COUNT_T)cchDir);
251-
252-
if (fname != NULL)
253-
fname->Set(wzFname, (COUNT_T)cchFname);
254-
255-
if (ext != NULL)
256-
ext->Set(wzExt, (COUNT_T)cchExt);
257-
}
258-

0 commit comments

Comments
 (0)