Commit 65f26902 authored by Andrew Eikum's avatar Andrew Eikum Committed by Alexandre Julliard

kernel32: Support extended pathnames in GetShortPathName.

parent 0d2817b1
...@@ -440,7 +440,7 @@ DWORD WINAPI GetLongPathNameA( LPCSTR shortpath, LPSTR longpath, DWORD longlen ) ...@@ -440,7 +440,7 @@ DWORD WINAPI GetLongPathNameA( LPCSTR shortpath, LPSTR longpath, DWORD longlen )
*/ */
DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortlen ) DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortlen )
{ {
WCHAR tmpshortpath[MAX_PATHNAME_LEN]; WCHAR *tmpshortpath;
LPCWSTR p; LPCWSTR p;
DWORD sp = 0, lp = 0; DWORD sp = 0, lp = 0;
DWORD tmplen; DWORD tmplen;
...@@ -460,12 +460,28 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl ...@@ -460,12 +460,28 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl
return 0; return 0;
} }
/* 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)
{
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 */ /* check for drive letter */
if (longpath[0] != '/' && longpath[1] == ':' ) if (longpath[lp] != '/' && longpath[lp + 1] == ':' )
{ {
tmpshortpath[0] = longpath[0]; tmpshortpath[sp] = longpath[lp];
tmpshortpath[1] = ':'; tmpshortpath[sp + 1] = ':';
sp = lp = 2; sp += 2;
lp += 2;
} }
while (longpath[lp]) while (longpath[lp])
...@@ -522,9 +538,11 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl ...@@ -522,9 +538,11 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl
tmplen--; /* length without 0 */ tmplen--; /* length without 0 */
} }
HeapFree(GetProcessHeap(), 0, tmpshortpath);
return tmplen; return tmplen;
notfound: notfound:
HeapFree(GetProcessHeap(), 0, tmpshortpath);
TRACE("not found!\n" ); TRACE("not found!\n" );
SetLastError ( ERROR_FILE_NOT_FOUND ); SetLastError ( ERROR_FILE_NOT_FOUND );
return 0; return 0;
......
...@@ -1343,29 +1343,44 @@ static void test_GetLongPathNameW(void) ...@@ -1343,29 +1343,44 @@ static void test_GetLongPathNameW(void)
static void test_GetShortPathNameW(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 }; static const WCHAR extended_prefix[] = {'\\','\\','?','\\',0};
WCHAR path[MAX_PATH]; 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]; WCHAR short_path[MAX_PATH];
DWORD length; DWORD length;
HANDLE file; HANDLE file;
int ret; int ret;
WCHAR name[] = { 't', 'e', 's', 't', 0 };
WCHAR backSlash[] = { '\\', 0 };
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
GetTempPathW( MAX_PATH, path ); GetTempPathW( MAX_PATH, tmppath );
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
{ {
win_skip("GetTempPathW is not implemented\n"); win_skip("GetTempPathW is not implemented\n");
return; return;
} }
lstrcpyW( path, tmppath );
lstrcatW( path, test_path ); lstrcatW( path, test_path );
lstrcatW( path, backSlash ); lstrcatW( path, backSlash );
ret = CreateDirectoryW( path, NULL ); ret = CreateDirectoryW( path, NULL );
ok( ret, "Directory was not created. LastError = %d\n", GetLastError() ); ok( ret, "Directory was not created. LastError = %d\n", GetLastError() );
/* Starting a main part of test */ /* 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 ); length = GetShortPathNameW( path, short_path, 0 );
ok( length, "GetShortPathNameW returned 0.\n" ); ok( length, "GetShortPathNameW returned 0.\n" );
ret = GetShortPathNameW( path, short_path, length ); ret = GetShortPathNameW( path, short_path, length );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment