kernel32: Fix incorrect lastpart in GetFullPathNameA with DBCS.

This commit is contained in:
Akihiro Sagawa 2014-10-14 00:24:58 +09:00 committed by Alexandre Julliard
parent c27af4774e
commit 4aea5ca72b
2 changed files with 28 additions and 10 deletions

View File

@ -251,12 +251,12 @@ DWORD WINAPI GetFullPathNameA( LPCSTR name, DWORD len, LPSTR buffer,
LPSTR *lastpart ) LPSTR *lastpart )
{ {
WCHAR *nameW; WCHAR *nameW;
WCHAR bufferW[MAX_PATH]; WCHAR bufferW[MAX_PATH], *lastpartW = NULL;
DWORD ret; DWORD ret;
if (!(nameW = FILE_name_AtoW( name, FALSE ))) return 0; if (!(nameW = FILE_name_AtoW( name, FALSE ))) return 0;
ret = GetFullPathNameW( nameW, MAX_PATH, bufferW, NULL); ret = GetFullPathNameW( nameW, MAX_PATH, bufferW, &lastpartW);
if (!ret) return 0; if (!ret) return 0;
if (ret > MAX_PATH) if (ret > MAX_PATH)
@ -267,14 +267,10 @@ DWORD WINAPI GetFullPathNameA( LPCSTR name, DWORD len, LPSTR buffer,
ret = copy_filename_WtoA( bufferW, buffer, len ); ret = copy_filename_WtoA( bufferW, buffer, len );
if (ret < len && lastpart) if (ret < len && lastpart)
{ {
LPSTR p = buffer + strlen(buffer) - 1; if (lastpartW)
*lastpart = buffer + FILE_name_WtoA( bufferW, lastpartW - bufferW, NULL, 0 );
if (*p != '\\') else
{ *lastpart = NULL;
while ((p > buffer + 2) && (*p != '\\')) p--;
*lastpart = p + 1;
}
else *lastpart = NULL;
} }
return ret; return ret;
} }

View File

@ -1828,6 +1828,7 @@ static void test_GetFullPathNameA(void)
char output[MAX_PATH], *filepart; char output[MAX_PATH], *filepart;
DWORD ret; DWORD ret;
int i; int i;
UINT acp;
const struct const struct
{ {
@ -1864,6 +1865,27 @@ static void test_GetFullPathNameA(void)
"[%d] Expected GetLastError() to return 0xdeadbeef, got %u\n", "[%d] Expected GetLastError() to return 0xdeadbeef, got %u\n",
i, GetLastError()); i, GetLastError());
} }
acp = GetACP();
if (acp != 932)
skip("Skipping DBCS(Japanese) GetFullPathNameA test in this codepage (%d)\n", acp);
else {
const struct dbcs_case {
const char *input;
const char *expected;
} testset[] = {
{ "c:\\a\\\x95\x5c\x97\xa0.txt", "\x95\x5c\x97\xa0.txt" },
{ "c:\\\x83\x8f\x83\x43\x83\x93\\wine.c", "wine.c" },
{ "c:\\demo\\\x97\xa0\x95\x5c", "\x97\xa0\x95\x5c" }
};
for (i = 0; i < sizeof(testset)/sizeof(testset[0]); i++) {
ret = GetFullPathNameA(testset[i].input, sizeof(output),
output, &filepart);
ok(ret, "[%d] GetFullPathName error %u\n", i, GetLastError());
ok(!lstrcmpA(filepart, testset[i].expected),
"[%d] expected %s got %s\n", i, testset[i].expected, filepart);
}
}
} }
static void test_GetFullPathNameW(void) static void test_GetFullPathNameW(void)