branch update for HEAD-2003050101
[reactos.git] / lib / kernel32 / file / dir.c
index 8736996..9c08898 100644 (file)
@@ -598,6 +598,7 @@ SearchPathW (
                                                len * sizeof(WCHAR));
                if (EnvironmentBufferW == NULL)
                {
+                       SetLastError(ERROR_OUTOFMEMORY);
                        return 0;
                }
 
@@ -614,13 +615,18 @@ SearchPathW (
                lpPath = EnvironmentBufferW;
        }
 
-       retCode = RtlDosSearchPath_U ((PWCHAR)lpPath, (PWCHAR)lpFileName, (PWCHAR)lpExtension, nBufferLength, lpBuffer, lpFilePart);
+       retCode = RtlDosSearchPath_U ((PWCHAR)lpPath, (PWCHAR)lpFileName, (PWCHAR)lpExtension, 
+                                     nBufferLength * sizeof(WCHAR), lpBuffer, lpFilePart);
 
        if (EnvironmentBufferW != NULL)
        {
                RtlFreeHeap(GetProcessHeap(), 0, EnvironmentBufferW);
        }
-       return retCode;
+       if (retCode == 0)
+       {
+               SetLastError(ERROR_FILE_NOT_FOUND);
+       }
+       return retCode / sizeof(WCHAR);
 }
 
 /* EOF */