Hi Paul, Here is the patch for GetLongPathNameW. Would you mind looking at it to see if it makes sense?
(Forgot to bottom post in the last message :-( ) Kind regards Alexandre -- -------------------------------------------------- Alexandre Hardy http://www.ahardy.za.net
From 99b08d8497491d52935335e8dd6f9173f68fbab8 Mon Sep 17 00:00:00 2001 From: Alexandre Hardy <[email protected]> Date: Fri, 11 Dec 2009 14:53:35 +0200 Subject: Handle non share UNC pathnames --- dlls/kernel32/path.c | 40 +++++++++++++++++++++++++++++++++++++--- dlls/kernel32/tests/path.c | 3 --- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c index e9463bb..168946a 100644 --- a/dlls/kernel32/path.c +++ b/dlls/kernel32/path.c @@ -44,6 +44,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(file); #define MAX_PATHNAME_LEN 1024 +#define MAX_LONGPATHNAME_LEN 32767 /* check if a file name is for an executable file (.exe or .com) */ @@ -290,7 +291,7 @@ DWORD WINAPI GetFullPathNameA( LPCSTR name, DWORD len, LPSTR buffer, */ DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen ) { - WCHAR tmplongpath[MAX_PATHNAME_LEN]; + LPWSTR tmplongpath; LPCWSTR p; DWORD sp = 0, lp = 0; DWORD tmplen; @@ -309,13 +310,44 @@ DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen return 0; } + if (!(tmplongpath = (WCHAR *)HeapAlloc( GetProcessHeap(), 0, MAX_LONGPATHNAME_LEN * sizeof(WCHAR) ))) { + SetLastError( ERROR_OUTOFMEMORY ); + return 0; + } + TRACE("%s,%p,%d\n", debugstr_w(shortpath), longpath, longlen); if (shortpath[0] == '\\' && shortpath[1] == '\\') { ERR("UNC pathname %s\n", debugstr_w(shortpath)); - lstrcpynW( longpath, shortpath, longlen ); - return strlenW(longpath); + + /* Handle extended length path */ + if (shortpath[2] == '?' && shortpath[3] == '\\') { + tmplen = GetLongPathNameW(shortpath + 4, tmplongpath, MAX_LONGPATHNAME_LEN); + if (tmplen == 0) { + HeapFree( GetProcessHeap(), 0, tmplongpath ); + return 0; + } + if (tmplen + 5 <= longlen) { + lstrcpynW(longpath, shortpath, 5); + lstrcatW(longpath, tmplongpath); + HeapFree( GetProcessHeap(), 0, tmplongpath ); + return tmplen + 4; + } else + HeapFree( GetProcessHeap(), 0, tmplongpath ); + return tmplen + 5; + } + + HeapFree( GetProcessHeap(), 0, tmplongpath ); + + /* Can't handle shares at the moment, just copy the filename + * But only if there is enough space in the buffer */ + tmplen = strlenW(shortpath); + if (longlen >= tmplen + 1) { + lstrcpynW( longpath, shortpath, longlen ); + return tmplen; + } + return tmplen + 1; } unixabsolute = (shortpath[0] == '/'); @@ -358,6 +390,7 @@ DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen { TRACE("not found %s!\n", debugstr_w(tmplongpath)); SetLastError ( ERROR_FILE_NOT_FOUND ); + HeapFree( GetProcessHeap(), 0, tmplongpath ); return 0; } FindClose(goit); @@ -379,6 +412,7 @@ DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen tmplen--; /* length without 0 */ } + HeapFree( GetProcessHeap(), 0, tmplongpath ); return tmplen; } diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c index c7e3dc7..c3b216d 100644 --- a/dlls/kernel32/tests/path.c +++ b/dlls/kernel32/tests/path.c @@ -1103,16 +1103,13 @@ static void test_GetLongPathNameW(void) lstrcpyW(longpath, uncprefix); lstrcatW(longpath, tempfile); length = pGetLongPathNameW(longpath,NULL,0); - todo_wine ok(lstrlenW(longpath) + 1==length,"GetLongPathNameW returned %d but expected %d\n",length, lstrlenW(longpath) + 1); lstrcpyW(shortpath, uncprefix); GetShortPathNameW(tempfile, shortpath + 4, MAX_PATH - 4); length = pGetLongPathNameW(shortpath,NULL,0); - todo_wine ok(lstrlenW(longpath) + 1==length,"GetLongPathNameW returned %d but expected %d\n",length, lstrlenW(longpath) + 1); - todo_wine length = pGetLongPathNameW(shortpath,temppath,MAX_PATH); ok(lstrlenW(longpath)==length,"GetLongPathNameW returned %d but expected %d\n",length, lstrlenW(longpath)); -- 1.6.2.1
