Hans Leidekker : wininet: Make FtpGetCurrentDirectoryA pass all todo_wine tests.

Alexandre Julliard julliard at winehq.org
Mon Dec 10 08:54:24 CST 2007


Module: wine
Branch: master
Commit: b529b3bb3264aa270bb1f6b176b8d12f2f572ea5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b529b3bb3264aa270bb1f6b176b8d12f2f572ea5

Author: Hans Leidekker <hans at it.vu.nl>
Date:   Sat Dec  8 22:54:43 2007 +0100

wininet: Make FtpGetCurrentDirectoryA pass all todo_wine tests.

---

 dlls/wininet/ftp.c       |   32 +++++++++++++++++---------------
 dlls/wininet/tests/ftp.c |   11 +++--------
 2 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index ce60fa0..ed3fbea 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -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);
diff --git a/dlls/wininet/tests/ftp.c b/dlls/wininet/tests/ftp.c
index 06bcc0b..985b23b 100644
--- a/dlls/wininet/tests/ftp.c
+++ b/dlls/wininet/tests/ftp.c
@@ -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());
 }
 




More information about the wine-cvs mailing list