wininet: Make FtpGetCurrentDirectoryA pass all todo_wine tests.

This commit is contained in:
Hans Leidekker 2007-12-08 22:54:43 +01:00 committed by Alexandre Julliard
parent c6dd1f1599
commit b529b3bb32
2 changed files with 20 additions and 23 deletions

View File

@ -844,13 +844,12 @@ BOOL WINAPI FtpGetCurrentDirectoryA(HINTERNET hFtpSession, LPSTR lpszCurrentDire
}
}
ret = FtpGetCurrentDirectoryW(hFtpSession, lpszCurrentDirectory?dir:NULL, lpdwCurrentDirectory?&len:NULL);
if(lpdwCurrentDirectory) {
*lpdwCurrentDirectory = len;
if(lpszCurrentDirectory) {
WideCharToMultiByte(CP_ACP, 0, dir, len, lpszCurrentDirectory, *lpdwCurrentDirectory, NULL, NULL);
HeapFree(GetProcessHeap(), 0, dir);
}
}
if (ret && lpszCurrentDirectory)
WideCharToMultiByte(CP_ACP, 0, dir, -1, lpszCurrentDirectory, len, NULL, NULL);
if (lpdwCurrentDirectory) *lpdwCurrentDirectory = len;
HeapFree(GetProcessHeap(), 0, dir);
return ret;
}
@ -965,8 +964,6 @@ BOOL WINAPI FTP_FtpGetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPWSTR lpszC
/* Clear any error information */
INTERNET_SetLastError(0);
ZeroMemory(lpszCurrentDirectory, *lpdwCurrentDirectory);
hIC = lpwfs->lpAppInfo;
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PWD, NULL,
lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
@ -978,7 +975,7 @@ BOOL WINAPI FTP_FtpGetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPWSTR lpszC
if (nResCode == 257) /* Extract directory name */
{
DWORD firstpos, lastpos, len;
LPWSTR lpszResponseBuffer = WININET_strdup_AtoW(INTERNET_GetResponseBuffer());
LPWSTR lpszResponseBuffer = WININET_strdup_AtoW(INTERNET_GetResponseBuffer());
for (firstpos = 0, lastpos = 0; lpszResponseBuffer[lastpos]; lastpos++)
{
@ -988,14 +985,19 @@ BOOL WINAPI FTP_FtpGetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPWSTR lpszC
firstpos = lastpos;
else
break;
}
}
}
len = lastpos - firstpos;
if (*lpdwCurrentDirectory >= len)
{
memcpy(lpszCurrentDirectory, &lpszResponseBuffer[firstpos + 1], len * sizeof(WCHAR));
lpszCurrentDirectory[len - 1] = 0;
*lpdwCurrentDirectory = len;
bSuccess = TRUE;
}
else INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
len = lastpos - firstpos - 1;
lstrcpynW(lpszCurrentDirectory, &lpszResponseBuffer[firstpos+1], *lpdwCurrentDirectory);
HeapFree(GetProcessHeap(), 0, lpszResponseBuffer);
*lpdwCurrentDirectory = len;
bSuccess = TRUE;
}
else
FTP_SetResponseError(nResCode);

View File

@ -746,21 +746,17 @@ static void test_get_current_dir(HINTERNET hFtp, HINTERNET hConnect)
SetLastError(0xdeadbeef);
bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n" );
todo_wine
ok ( lstrcmp(lpszCurrentDirectory, "/pub") == 0, "Expected returned value \"%s\" to match \"%s\"\n", (char*)lpszCurrentDirectory, "/pub");
ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory);
ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
/* test for the current directory with a size only large enough to
* fit the string and not the null terminating character */
SetLastError(0xdeadbeef);
dwCurrentDirectoryLen = 4;
lpszCurrentDirectory[4] = 'a'; /* set position 4 of the array to something else to make sure a leftover \0 isn't fooling the test */
bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
todo_wine
ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n");
ok ( lstrcmp(lpszCurrentDirectory, "/pub") != 0, "Expected returned value \"%s\" to not match \"%s\"\n", (char*)lpszCurrentDirectory, "/pub");
todo_wine
ok ( strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to not match \"/pub\"\n", lpszCurrentDirectory);
ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError());
/* test for the current directory with a size large enough to store
@ -769,8 +765,7 @@ todo_wine
dwCurrentDirectoryLen = 5;
bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen );
ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n");
todo_wine
ok ( lstrcmp(lpszCurrentDirectory, "/pub") == 0, "Expected returned value \"%s\" to match \"%s\"\n", (char*)lpszCurrentDirectory, "/pub");
ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory);
ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %d\n", GetLastError());
}