Commit b529b3bb authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wininet: Make FtpGetCurrentDirectoryA pass all todo_wine tests.

parent c6dd1f15
......@@ -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);
......
......@@ -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());
}
......
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