kernel32: Support extended pathnames in GetShortPathName.
This commit is contained in:
parent
0d2817b161
commit
65f2690203
|
@ -440,7 +440,7 @@ DWORD WINAPI GetLongPathNameA( LPCSTR shortpath, LPSTR longpath, DWORD longlen )
|
|||
*/
|
||||
DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortlen )
|
||||
{
|
||||
WCHAR tmpshortpath[MAX_PATHNAME_LEN];
|
||||
WCHAR *tmpshortpath;
|
||||
LPCWSTR p;
|
||||
DWORD sp = 0, lp = 0;
|
||||
DWORD tmplen;
|
||||
|
@ -460,12 +460,28 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* check for drive letter */
|
||||
if (longpath[0] != '/' && longpath[1] == ':' )
|
||||
/* code below only removes characters from string, never adds, so this is
|
||||
* the largest buffer that tmpshortpath will need to have */
|
||||
tmpshortpath = HeapAlloc(GetProcessHeap(), 0, (strlenW(longpath) + 1) * sizeof(WCHAR));
|
||||
if (!tmpshortpath)
|
||||
{
|
||||
tmpshortpath[0] = longpath[0];
|
||||
tmpshortpath[1] = ':';
|
||||
sp = lp = 2;
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (longpath[0] == '\\' && longpath[1] == '\\' && longpath[2] == '?' && longpath[3] == '\\')
|
||||
{
|
||||
memcpy(tmpshortpath, longpath, 4 * sizeof(WCHAR));
|
||||
sp = lp = 4;
|
||||
}
|
||||
|
||||
/* check for drive letter */
|
||||
if (longpath[lp] != '/' && longpath[lp + 1] == ':' )
|
||||
{
|
||||
tmpshortpath[sp] = longpath[lp];
|
||||
tmpshortpath[sp + 1] = ':';
|
||||
sp += 2;
|
||||
lp += 2;
|
||||
}
|
||||
|
||||
while (longpath[lp])
|
||||
|
@ -522,9 +538,11 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl
|
|||
tmplen--; /* length without 0 */
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, tmpshortpath);
|
||||
return tmplen;
|
||||
|
||||
notfound:
|
||||
HeapFree(GetProcessHeap(), 0, tmpshortpath);
|
||||
TRACE("not found!\n" );
|
||||
SetLastError ( ERROR_FILE_NOT_FOUND );
|
||||
return 0;
|
||||
|
|
|
@ -1343,29 +1343,44 @@ static void test_GetLongPathNameW(void)
|
|||
|
||||
static void test_GetShortPathNameW(void)
|
||||
{
|
||||
WCHAR test_path[] = { 'L', 'o', 'n', 'g', 'D', 'i', 'r', 'e', 'c', 't', 'o', 'r', 'y', 'N', 'a', 'm', 'e', 0 };
|
||||
WCHAR path[MAX_PATH];
|
||||
static const WCHAR extended_prefix[] = {'\\','\\','?','\\',0};
|
||||
static const WCHAR test_path[] = { 'L', 'o', 'n', 'g', 'D', 'i', 'r', 'e', 'c', 't', 'o', 'r', 'y', 'N', 'a', 'm', 'e', 0 };
|
||||
static const WCHAR name[] = { 't', 'e', 's', 't', 0 };
|
||||
static const WCHAR backSlash[] = { '\\', 0 };
|
||||
WCHAR path[MAX_PATH], tmppath[MAX_PATH];
|
||||
WCHAR short_path[MAX_PATH];
|
||||
DWORD length;
|
||||
HANDLE file;
|
||||
int ret;
|
||||
WCHAR name[] = { 't', 'e', 's', 't', 0 };
|
||||
WCHAR backSlash[] = { '\\', 0 };
|
||||
|
||||
SetLastError(0xdeadbeef);
|
||||
GetTempPathW( MAX_PATH, path );
|
||||
GetTempPathW( MAX_PATH, tmppath );
|
||||
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
||||
{
|
||||
win_skip("GetTempPathW is not implemented\n");
|
||||
return;
|
||||
}
|
||||
|
||||
lstrcpyW( path, tmppath );
|
||||
lstrcatW( path, test_path );
|
||||
lstrcatW( path, backSlash );
|
||||
ret = CreateDirectoryW( path, NULL );
|
||||
ok( ret, "Directory was not created. LastError = %d\n", GetLastError() );
|
||||
|
||||
/* Starting a main part of test */
|
||||
|
||||
/* extended path \\?\C:\path\ */
|
||||
lstrcpyW( path, extended_prefix );
|
||||
lstrcatW( path, tmppath );
|
||||
lstrcatW( path, test_path );
|
||||
lstrcatW( path, backSlash );
|
||||
short_path[0] = 0;
|
||||
length = GetShortPathNameW( path, short_path, sizeof(short_path) / sizeof(*short_path) );
|
||||
ok( length, "GetShortPathNameW returned 0.\n" );
|
||||
|
||||
lstrcpyW( path, tmppath );
|
||||
lstrcatW( path, test_path );
|
||||
lstrcatW( path, backSlash );
|
||||
length = GetShortPathNameW( path, short_path, 0 );
|
||||
ok( length, "GetShortPathNameW returned 0.\n" );
|
||||
ret = GetShortPathNameW( path, short_path, length );
|
||||
|
|
Loading…
Reference in New Issue