Dmitry Timoshkov : kernel32: GetShortPathName for a non-existent short file name should fail.
Module: wine Branch: master Commit: 4cc482bc0df758bec76ad1466abcba7f85e3cc5c URL: http://source.winehq.org/git/wine.git/?a=commit;h=4cc482bc0df758bec76ad1466a... Author: Dmitry Timoshkov <dmitry(a)baikal.ru> Date: Fri Jul 19 14:02:38 2013 +0900 kernel32: GetShortPathName for a non-existent short file name should fail. --- dlls/kernel32/path.c | 30 ++++++++---------------------- dlls/kernel32/tests/path.c | 2 -- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c index 63d977b..5cd3c4b 100644 --- a/dlls/kernel32/path.c +++ b/dlls/kernel32/path.c @@ -441,8 +441,6 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl DWORD tmplen; WIN32_FIND_DATAW wfd; HANDLE goit; - UNICODE_STRING ustr; - WCHAR ustr_buf[8+1+3+1]; TRACE("%s\n", debugstr_w(longpath)); @@ -465,10 +463,6 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl sp = lp = 2; } - ustr.Buffer = ustr_buf; - ustr.Length = 0; - ustr.MaximumLength = sizeof(ustr_buf); - while (longpath[lp]) { /* check for path delimiters and reproduce them */ @@ -485,29 +479,21 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl continue; } - for (p = longpath + lp; *p && *p != '/' && *p != '\\'; p++); - tmplen = p - (longpath + lp); - lstrcpynW(tmpshortpath + sp, longpath + lp, tmplen + 1); - /* Check, if the current element is a valid dos name */ - if (tmplen <= 8+1+3) + p = longpath + lp; + if (lp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\')) { - BOOLEAN spaces; - memcpy(ustr_buf, longpath + lp, tmplen * sizeof(WCHAR)); - ustr_buf[tmplen] = '\0'; - ustr.Length = tmplen * sizeof(WCHAR); - if (RtlIsNameLegalDOS8Dot3(&ustr, NULL, &spaces) && !spaces) - { - sp += tmplen; - lp += tmplen; - continue; - } + tmpshortpath[sp++] = *p++; + tmpshortpath[sp++] = *p++; } + for (; *p && *p != '/' && *p != '\\'; p++); + tmplen = p - (longpath + lp); + lstrcpynW(tmpshortpath + sp, longpath + lp, tmplen + 1); /* Check if the file exists and use the existing short file name */ goit = FindFirstFileW(tmpshortpath, &wfd); if (goit == INVALID_HANDLE_VALUE) goto notfound; FindClose(goit); - strcpyW(tmpshortpath + sp, wfd.cAlternateFileName); + strcpyW(tmpshortpath + sp, wfd.cAlternateFileName[0] ? wfd.cAlternateFileName : wfd.cFileName); sp += strlenW(tmpshortpath + sp); lp += tmplen; } diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c index d703aa9..c49a76f 100644 --- a/dlls/kernel32/tests/path.c +++ b/dlls/kernel32/tests/path.c @@ -1281,9 +1281,7 @@ static void test_GetShortPathNameW(void) /* GetShortPathName for a non-existent short file name should fail */ SetLastError(0xdeadbeef); length = GetShortPathNameW( short_path, path, 0 ); -todo_wine ok(!length, "GetShortPathNameW should fail\n"); -todo_wine ok(GetLastError() == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); file = CreateFileW( short_path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
participants (1)
-
Alexandre Julliard