Commit in reactos/lib on MAIN
kernel32/file/dir.c+529-5011.44 -> 1.45
ntdll/ldr/utils.c+611-5991.86 -> 1.87
+1140-1100
2 modified files
Patch by Pablo Borobia <pablog7@argentina.com>
Correct search path for DLL loading (including directory from which .exe
was loaded).

reactos/lib/kernel32/file
dir.c 1.44 -> 1.45
diff -u -r1.44 -r1.45
--- dir.c	23 Jan 2004 21:16:03 -0000	1.44
+++ dir.c	2 Jun 2004 18:26:57 -0000	1.45
@@ -1,4 +1,4 @@
-/* $Id: dir.c,v 1.44 2004/01/23 21:16:03 ekohl Exp $
+/* $Id: dir.c,v 1.45 2004/06/02 18:26:57 gvg Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -29,13 +29,13 @@
 BOOL
 STDCALL
 CreateDirectoryA (
-	LPCSTR			lpPathName,
-	LPSECURITY_ATTRIBUTES	lpSecurityAttributes
-	)
-{
-	return CreateDirectoryExA (NULL,
-	                           lpPathName,
-	                           lpSecurityAttributes);
+        LPCSTR                  lpPathName,
+        LPSECURITY_ATTRIBUTES   lpSecurityAttributes
+        )
+{
+        return CreateDirectoryExA (NULL,
+                                   lpPathName,
+                                   lpSecurityAttributes);
 }
 
 
@@ -45,69 +45,69 @@
 BOOL
 STDCALL
 CreateDirectoryExA (
-	LPCSTR			lpTemplateDirectory,
-	LPCSTR			lpNewDirectory,
-	LPSECURITY_ATTRIBUTES	lpSecurityAttributes)
-{
-	UNICODE_STRING TmplDirU;
-	UNICODE_STRING NewDirU;
-	ANSI_STRING TmplDir;
-	ANSI_STRING NewDir;
-	BOOL Result;
-
-	RtlInitUnicodeString (&TmplDirU,
-	                      NULL);
-
-	RtlInitUnicodeString (&NewDirU,
-	                      NULL);
-
-	if (lpTemplateDirectory != NULL)
-	{
-		RtlInitAnsiString (&TmplDir,
-		                   (LPSTR)lpTemplateDirectory);
-
-		/* convert ansi (or oem) string to unicode */
-		if (bIsFileApiAnsi)
-			RtlAnsiStringToUnicodeString (&TmplDirU,
-			                              &TmplDir,
-			                              TRUE);
-		else
-			RtlOemStringToUnicodeString (&TmplDirU,
-			                             &TmplDir,
-			                             TRUE);
-	}
-
-	if (lpNewDirectory != NULL)
-	{
-		RtlInitAnsiString (&NewDir,
-		                   (LPSTR)lpNewDirectory);
-
-		/* convert ansi (or oem) string to unicode */
-		if (bIsFileApiAnsi)
-			RtlAnsiStringToUnicodeString (&NewDirU,
-			                              &NewDir,
-			                              TRUE);
-		else
-			RtlOemStringToUnicodeString (&NewDirU,
-			                             &NewDir,
-			                             TRUE);
-	}
-
-	Result = CreateDirectoryExW (TmplDirU.Buffer,
-	                             NewDirU.Buffer,
-	                             lpSecurityAttributes);
-
-	if (lpTemplateDirectory != NULL)
-		RtlFreeHeap (RtlGetProcessHeap (),
-		             0,
-		             TmplDirU.Buffer);
-
-	if (lpNewDirectory != NULL)
-		RtlFreeHeap (RtlGetProcessHeap (),
-		             0,
-		             NewDirU.Buffer);
+        LPCSTR                  lpTemplateDirectory,
+        LPCSTR                  lpNewDirectory,
+        LPSECURITY_ATTRIBUTES   lpSecurityAttributes)
+{
+        UNICODE_STRING TmplDirU;
+        UNICODE_STRING NewDirU;
+        ANSI_STRING TmplDir;
+        ANSI_STRING NewDir;
+        BOOL Result;
+
+        RtlInitUnicodeString (&TmplDirU,
+                              NULL);
+
+        RtlInitUnicodeString (&NewDirU,
+                              NULL);
+
+        if (lpTemplateDirectory != NULL)
+        {
+                RtlInitAnsiString (&TmplDir,
+                                   (LPSTR)lpTemplateDirectory);
+
+                /* convert ansi (or oem) string to unicode */
+                if (bIsFileApiAnsi)
+                        RtlAnsiStringToUnicodeString (&TmplDirU,
+                                                      &TmplDir,
+                                                      TRUE);
+                else
+                        RtlOemStringToUnicodeString (&TmplDirU,
+                                                     &TmplDir,
+                                                     TRUE);
+        }
+
+        if (lpNewDirectory != NULL)
+        {
+                RtlInitAnsiString (&NewDir,
+                                   (LPSTR)lpNewDirectory);
+
+                /* convert ansi (or oem) string to unicode */
+                if (bIsFileApiAnsi)
+                        RtlAnsiStringToUnicodeString (&NewDirU,
+                                                      &NewDir,
+                                                      TRUE);
+                else
+                        RtlOemStringToUnicodeString (&NewDirU,
+                                                     &NewDir,
+                                                     TRUE);
+        }
+
+        Result = CreateDirectoryExW (TmplDirU.Buffer,
+                                     NewDirU.Buffer,
+                                     lpSecurityAttributes);
+
+        if (lpTemplateDirectory != NULL)
+                RtlFreeHeap (RtlGetProcessHeap (),
+                             0,
+                             TmplDirU.Buffer);
+
+        if (lpNewDirectory != NULL)
+                RtlFreeHeap (RtlGetProcessHeap (),
+                             0,
+                             NewDirU.Buffer);
 
-	return Result;
+        return Result;
 }
 
 
@@ -117,13 +117,13 @@
 BOOL
 STDCALL
 CreateDirectoryW (
-	LPCWSTR			lpPathName,
-	LPSECURITY_ATTRIBUTES	lpSecurityAttributes
-	)
-{
-	return CreateDirectoryExW (NULL,
-	                           lpPathName,
-	                           lpSecurityAttributes);
+        LPCWSTR                 lpPathName,
+        LPSECURITY_ATTRIBUTES   lpSecurityAttributes
+        )
+{
+        return CreateDirectoryExW (NULL,
+                                   lpPathName,
+                                   lpSecurityAttributes);
 }
 
 
@@ -133,20 +133,20 @@
 BOOL
 STDCALL
 CreateDirectoryExW (
-	LPCWSTR			lpTemplateDirectory,
-	LPCWSTR			lpNewDirectory,
-	LPSECURITY_ATTRIBUTES	lpSecurityAttributes
-	)
-{
-	OBJECT_ATTRIBUTES ObjectAttributes;
-	IO_STATUS_BLOCK IoStatusBlock;
-	UNICODE_STRING NtPathU;
-	HANDLE DirectoryHandle;
-	NTSTATUS Status;
-
-	DPRINT ("lpTemplateDirectory %S lpNewDirectory %S lpSecurityAttributes %p\n",
-	        lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes);
-  
+        LPCWSTR                 lpTemplateDirectory,
+        LPCWSTR                 lpNewDirectory,
+        LPSECURITY_ATTRIBUTES   lpSecurityAttributes
+        )
+{
+        OBJECT_ATTRIBUTES ObjectAttributes;
+        IO_STATUS_BLOCK IoStatusBlock;
+        UNICODE_STRING NtPathU;
+        HANDLE DirectoryHandle;
+        NTSTATUS Status;
+
+        DPRINT ("lpTemplateDirectory %S lpNewDirectory %S lpSecurityAttributes %p\n",
+                lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes);
+
   // Can't create empty directory
   if(lpNewDirectory == NULL || *lpNewDirectory == 0)
   {
@@ -154,54 +154,54 @@
     return FALSE;
   }
 
-	if (lpTemplateDirectory != NULL && *lpTemplateDirectory != 0)
-	{
-		// get object attributes from template directory
-		DPRINT("KERNEL32:FIXME:%s:%d\n",__FILE__,__LINE__);
-		return FALSE;
-	}
-
-	if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpNewDirectory,
-	                                   &NtPathU,
-	                                   NULL,
-	                                   NULL))
-		return FALSE;
-
-	DPRINT ("NtPathU \'%wZ\'\n", &NtPathU);
-
-	ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
-	ObjectAttributes.RootDirectory = NULL;
-	ObjectAttributes.ObjectName = &NtPathU;
-	ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE | OBJ_INHERIT;
-	ObjectAttributes.SecurityDescriptor = NULL;
-	ObjectAttributes.SecurityQualityOfService = NULL;
-
-	Status = NtCreateFile (&DirectoryHandle,
-	                       DIRECTORY_ALL_ACCESS,
-	                       &ObjectAttributes,
-	                       &IoStatusBlock,
-	                       NULL,
-	                       FILE_ATTRIBUTE_DIRECTORY,
-	                       0,
-	                       FILE_CREATE,
-	                       FILE_DIRECTORY_FILE,
-	                       NULL,
-	                       0);
-	DPRINT("Status: %lx\n", Status);
-
-	RtlFreeHeap (RtlGetProcessHeap (),
-	             0,
-	             NtPathU.Buffer);
-
-	if (!NT_SUCCESS(Status))
-	{
-		SetLastErrorByStatus(Status);
-		return FALSE;
-	}
+        if (lpTemplateDirectory != NULL && *lpTemplateDirectory != 0)
+        {
+                // get object attributes from template directory
+                DPRINT("KERNEL32:FIXME:%s:%d\n",__FILE__,__LINE__);
+                return FALSE;
+        }
+
+        if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpNewDirectory,
+                                           &NtPathU,
+                                           NULL,
+                                           NULL))
+                return FALSE;
+
+        DPRINT ("NtPathU \'%wZ\'\n", &NtPathU);
+
+        ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
+        ObjectAttributes.RootDirectory = NULL;
+        ObjectAttributes.ObjectName = &NtPathU;
+        ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE | OBJ_INHERIT;
+        ObjectAttributes.SecurityDescriptor = NULL;
+        ObjectAttributes.SecurityQualityOfService = NULL;
+
+        Status = NtCreateFile (&DirectoryHandle,
+                               DIRECTORY_ALL_ACCESS,
+                               &ObjectAttributes,
+                               &IoStatusBlock,
+                               NULL,
+                               FILE_ATTRIBUTE_DIRECTORY,
+                               0,
+                               FILE_CREATE,
+                               FILE_DIRECTORY_FILE,
+                               NULL,
+                               0);
+        DPRINT("Status: %lx\n", Status);
+
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     NtPathU.Buffer);
+
+        if (!NT_SUCCESS(Status))
+        {
+                SetLastErrorByStatus(Status);
+                return FALSE;
+        }
 
-	NtClose (DirectoryHandle);
+        NtClose (DirectoryHandle);
 
-	return TRUE;
+        return TRUE;
 }
 
 
@@ -211,33 +211,33 @@
 BOOL
 STDCALL
 RemoveDirectoryA (
-	LPCSTR	lpPathName
-	)
+        LPCSTR  lpPathName
+        )
 {
-	UNICODE_STRING PathNameU;
-	ANSI_STRING PathName;
-	BOOL Result;
-
-	RtlInitAnsiString (&PathName,
-	                   (LPSTR)lpPathName);
-
-	/* convert ansi (or oem) string to unicode */
-	if (bIsFileApiAnsi)
-		RtlAnsiStringToUnicodeString (&PathNameU,
-		                              &PathName,
-		                              TRUE);
-	else
-		RtlOemStringToUnicodeString (&PathNameU,
-		                             &PathName,
-		                             TRUE);
-
-	Result = RemoveDirectoryW (PathNameU.Buffer);
-
-	RtlFreeHeap (RtlGetProcessHeap (),
-	             0,
-	             PathNameU.Buffer);
+        UNICODE_STRING PathNameU;
+        ANSI_STRING PathName;
+        BOOL Result;
+
+        RtlInitAnsiString (&PathName,
+                           (LPSTR)lpPathName);
+
+        /* convert ansi (or oem) string to unicode */
+        if (bIsFileApiAnsi)
+                RtlAnsiStringToUnicodeString (&PathNameU,
+                                              &PathName,
+                                              TRUE);
+        else
+                RtlOemStringToUnicodeString (&PathNameU,
+                                             &PathName,
+                                             TRUE);
+
+        Result = RemoveDirectoryW (PathNameU.Buffer);
+
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     PathNameU.Buffer);
 
-	return Result;
+        return Result;
 }
 
 
@@ -247,80 +247,80 @@
 BOOL
 STDCALL
 RemoveDirectoryW (
-	LPCWSTR	lpPathName
-	)
+        LPCWSTR lpPathName
+        )
 {
-	FILE_DISPOSITION_INFORMATION FileDispInfo;
-	OBJECT_ATTRIBUTES ObjectAttributes;
-	IO_STATUS_BLOCK IoStatusBlock;
-	UNICODE_STRING NtPathU;
-	HANDLE DirectoryHandle;
-	NTSTATUS Status;
-
-	DPRINT("lpPathName %S\n", lpPathName);
-
-	if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpPathName,
-	                                   &NtPathU,
-	                                   NULL,
-	                                   NULL))
-		return FALSE;
-
-	ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
-	ObjectAttributes.RootDirectory = NULL;
-	ObjectAttributes.ObjectName = &NtPathU;
-	ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
-	ObjectAttributes.SecurityDescriptor = NULL;
-	ObjectAttributes.SecurityQualityOfService = NULL;
-
-	DPRINT("NtPathU '%S'\n", NtPathU.Buffer);
-
-	Status = NtCreateFile (&DirectoryHandle,
-	                       FILE_WRITE_ATTRIBUTES,    /* 0x110080 */
-	                       &ObjectAttributes,
-	                       &IoStatusBlock,
-	                       NULL,
-	                       FILE_ATTRIBUTE_DIRECTORY, /* 0x7 */
-	                       0,
-	                       FILE_OPEN,
-	                       FILE_DIRECTORY_FILE,      /* 0x204021 */
-	                       NULL,
-	                       0);
-
-	RtlFreeHeap (RtlGetProcessHeap (),
-	             0,
-	             NtPathU.Buffer);
-
-	if (!NT_SUCCESS(Status))
-	{
-		CHECKPOINT;
-		SetLastErrorByStatus (Status);
-		return FALSE;
-	}
-
-	FileDispInfo.DoDeleteFile = TRUE;
-
-	Status = NtSetInformationFile (DirectoryHandle,
-	                               &IoStatusBlock,
-	                               &FileDispInfo,
-	                               sizeof(FILE_DISPOSITION_INFORMATION),
-	                               FileDispositionInformation);
-	if (!NT_SUCCESS(Status))
-	{
-		CHECKPOINT;
-		NtClose(DirectoryHandle);
-		SetLastErrorByStatus (Status);
-		return FALSE;
-	}
-
-	Status = NtClose (DirectoryHandle);
-	if (!NT_SUCCESS(Status))
-	{
-		CHECKPOINT;
-		SetLastErrorByStatus (Status);
-		return FALSE;
-	}
+        FILE_DISPOSITION_INFORMATION FileDispInfo;
+        OBJECT_ATTRIBUTES ObjectAttributes;
+        IO_STATUS_BLOCK IoStatusBlock;
+        UNICODE_STRING NtPathU;
+        HANDLE DirectoryHandle;
+        NTSTATUS Status;
+
+        DPRINT("lpPathName %S\n", lpPathName);
+
+        if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpPathName,
+                                           &NtPathU,
+                                           NULL,
+                                           NULL))
+                return FALSE;
+
+        ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
+        ObjectAttributes.RootDirectory = NULL;
+        ObjectAttributes.ObjectName = &NtPathU;
+        ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
+        ObjectAttributes.SecurityDescriptor = NULL;
+        ObjectAttributes.SecurityQualityOfService = NULL;
+
+        DPRINT("NtPathU '%S'\n", NtPathU.Buffer);
+
+        Status = NtCreateFile (&DirectoryHandle,
+                               FILE_WRITE_ATTRIBUTES,    /* 0x110080 */
+                               &ObjectAttributes,
+                               &IoStatusBlock,
+                               NULL,
+                               FILE_ATTRIBUTE_DIRECTORY, /* 0x7 */
+                               0,
+                               FILE_OPEN,
+                               FILE_DIRECTORY_FILE,      /* 0x204021 */
+                               NULL,
+                               0);
+
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     NtPathU.Buffer);
+
+        if (!NT_SUCCESS(Status))
+        {
+                CHECKPOINT;
+                SetLastErrorByStatus (Status);
+                return FALSE;
+        }
+
+        FileDispInfo.DoDeleteFile = TRUE;
+
+        Status = NtSetInformationFile (DirectoryHandle,
+                                       &IoStatusBlock,
+                                       &FileDispInfo,
+                                       sizeof(FILE_DISPOSITION_INFORMATION),
+                                       FileDispositionInformation);
+        if (!NT_SUCCESS(Status))
+        {
+                CHECKPOINT;
+                NtClose(DirectoryHandle);
+                SetLastErrorByStatus (Status);
+                return FALSE;
+        }
+
+        Status = NtClose (DirectoryHandle);
+        if (!NT_SUCCESS(Status))
+        {
+                CHECKPOINT;
+                SetLastErrorByStatus (Status);
+                return FALSE;
+        }
 
-	return TRUE;
+        return TRUE;
 }
 
 
@@ -330,76 +330,76 @@
 DWORD
 STDCALL
 GetFullPathNameA (
-	LPCSTR	lpFileName,
-	DWORD	nBufferLength,
-	LPSTR	lpBuffer,
-	LPSTR	*lpFilePart
-	)
-{
-	UNICODE_STRING nameW;
-	WCHAR bufferW[MAX_PATH];
-	DWORD ret, retW;
-	LPWSTR FilePart = NULL;
-
-	DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, "
-	       "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
-
-	if (!lpFileName)
-	{
-		SetLastError(ERROR_INVALID_PARAMETER);
-		return 0;
-	}
-
-	if (!RtlCreateUnicodeStringFromAsciiz(&nameW, (LPSTR)lpFileName))
-	{
-		SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-		return 0;
-	}
-
-	if (lpFilePart)
-	{
-		*lpFilePart = NULL;
-	}
-
-	retW = GetFullPathNameW(nameW.Buffer, MAX_PATH, bufferW, &FilePart);
-
-	if (!retW)
-	{
-		ret = 0;
-	}
-	else if (retW > MAX_PATH)
-	{
-		SetLastError(ERROR_FILENAME_EXCED_RANGE);
-		ret = 0;
-	}
-	else
-	{
-	        ANSI_STRING AnsiBuffer;
-	        UNICODE_STRING UnicodeBuffer;
-
-		UnicodeBuffer.Length = wcslen(bufferW) * sizeof(WCHAR);
-		ret = nameW.Length;
-		if (nameW.Length <= nBufferLength)
-		{
-			UnicodeBuffer.Buffer = bufferW;
-			AnsiBuffer.MaximumLength = nBufferLength;
-			AnsiBuffer.Length = 0;
-			AnsiBuffer.Buffer = lpBuffer;
-			RtlUnicodeStringToAnsiString(&AnsiBuffer, &UnicodeBuffer, FALSE);
-
-			if (lpFilePart && FilePart != NULL)
-			{
-				*lpFilePart = (FilePart - bufferW) + lpBuffer;
-			}
-		}
-	}
+        LPCSTR  lpFileName,
+        DWORD   nBufferLength,
+        LPSTR   lpBuffer,
+        LPSTR   *lpFilePart
+        )
+{
+        UNICODE_STRING nameW;
+        WCHAR bufferW[MAX_PATH];
+        DWORD ret, retW;
+        LPWSTR FilePart = NULL;
+
+        DPRINT("GetFullPathNameA(lpFileName %s, nBufferLength %d, lpBuffer %p, "
+               "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
+
+        if (!lpFileName)
+        {
+                SetLastError(ERROR_INVALID_PARAMETER);
+                return 0;
+        }
+
+        if (!RtlCreateUnicodeStringFromAsciiz(&nameW, (LPSTR)lpFileName))
+        {
+                SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                return 0;
+        }
+
+        if (lpFilePart)
+        {
+                *lpFilePart = NULL;
+        }
+
+        retW = GetFullPathNameW(nameW.Buffer, MAX_PATH, bufferW, &FilePart);
+
+        if (!retW)
+        {
+                ret = 0;
+        }
+        else if (retW > MAX_PATH)
+        {
+                SetLastError(ERROR_FILENAME_EXCED_RANGE);
+                ret = 0;
+        }
+        else
+        {
+                ANSI_STRING AnsiBuffer;
+                UNICODE_STRING UnicodeBuffer;
+
+                UnicodeBuffer.Length = wcslen(bufferW) * sizeof(WCHAR);
+                ret = nameW.Length;
+                if (nameW.Length <= nBufferLength)
+                {
+                        UnicodeBuffer.Buffer = bufferW;
+                        AnsiBuffer.MaximumLength = nBufferLength;
+                        AnsiBuffer.Length = 0;
+                        AnsiBuffer.Buffer = lpBuffer;
+                        RtlUnicodeStringToAnsiString(&AnsiBuffer, &UnicodeBuffer, FALSE);
+
+                        if (lpFilePart && FilePart != NULL)
+                        {
+                                *lpFilePart = (FilePart - bufferW) + lpBuffer;
+                        }
+                }
+        }
 
-	RtlFreeUnicodeString(&nameW);
+        RtlFreeUnicodeString(&nameW);
 
-	DPRINT("lpBuffer %s lpFilePart %s Length %ld\n",
-	       lpBuffer, (lpFilePart == NULL) ? "NULL" : *lpFilePart, nameW.Length);
+        DPRINT("lpBuffer %s lpFilePart %s Length %ld\n",
+               lpBuffer, (lpFilePart == NULL) ? "NULL" : *lpFilePart, nameW.Length);
 
-	return ret;
+        return ret;
 }
 
 
@@ -409,26 +409,26 @@
 DWORD
 STDCALL
 GetFullPathNameW (
-	LPCWSTR	lpFileName,
-	DWORD	nBufferLength,
-	LPWSTR	lpBuffer,
-	LPWSTR	*lpFilePart
-	)
-{
-	ULONG Length;
-
-	DPRINT("GetFullPathNameW(lpFileName %S, nBufferLength %d, lpBuffer %p, "
-	       "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
-
-	Length = RtlGetFullPathName_U ((LPWSTR)lpFileName,
-	                               nBufferLength * sizeof(WCHAR),
-	                               lpBuffer,
-	                               lpFilePart);
+        LPCWSTR lpFileName,
+        DWORD   nBufferLength,
+        LPWSTR  lpBuffer,
+        LPWSTR  *lpFilePart
+        )
+{
+        ULONG Length;
+
+        DPRINT("GetFullPathNameW(lpFileName %S, nBufferLength %d, lpBuffer %p, "
+               "lpFilePart %p)\n",lpFileName,nBufferLength,lpBuffer,lpFilePart);
+
+        Length = RtlGetFullPathName_U ((LPWSTR)lpFileName,
+                                       nBufferLength * sizeof(WCHAR),
+                                       lpBuffer,
+                                       lpFilePart);
 
-	DPRINT("lpBuffer %S lpFilePart %S Length %ld\n",
-	       lpBuffer, (lpFilePart == NULL) ? L"NULL" : *lpFilePart, Length / sizeof(WCHAR));
+        DPRINT("lpBuffer %S lpFilePart %S Length %ld\n",
+               lpBuffer, (lpFilePart == NULL) ? L"NULL" : *lpFilePart, Length / sizeof(WCHAR));
 
-	return (Length / sizeof(WCHAR));
+        return (Length / sizeof(WCHAR));
 }
 
 
@@ -438,23 +438,23 @@
 DWORD
 STDCALL
 GetShortPathNameA (
-	LPCSTR	lpszLongPath,
-	LPSTR	lpszShortPath,
-	DWORD	cchBuffer
-	)
-{
-	//1 remove unicode chars and spaces
-	//2 remove preceding and trailing periods.
-	//3 remove embedded periods except the last one
-	
-	//4 Split the string in two parts before and after the period
-	//	truncate the part before the period to 6 chars and add ~1
-	//	truncate the part after the period to 3 chars
-	//3 Put the new name in uppercase
-	
-	//4 Increment the ~1 string if the resulting name allready exists
+        LPCSTR  lpszLongPath,
+        LPSTR   lpszShortPath,
+        DWORD   cchBuffer
+        )
+{
+        //1 remove unicode chars and spaces
+        //2 remove preceding and trailing periods.
+        //3 remove embedded periods except the last one
+
+        //4 Split the string in two parts before and after the period
+        //      truncate the part before the period to 6 chars and add ~1
+        //      truncate the part after the period to 3 chars
+        //3 Put the new name in uppercase
 
-	return 0;
+        //4 Increment the ~1 string if the resulting name allready exists
+
+        return 0;
 }
 
 
@@ -464,12 +464,12 @@
 DWORD
 STDCALL
 GetShortPathNameW (
-	LPCWSTR	lpszLongPath,
-	LPWSTR	lpszShortPath,
-	DWORD	cchBuffer
-	)
+        LPCWSTR lpszLongPath,
+        LPWSTR  lpszShortPath,
+        DWORD   cchBuffer
+        )
 {
-	return 0;
+        return 0;
 }
 
 
@@ -479,111 +479,111 @@
 DWORD
 STDCALL
 SearchPathA (
-	LPCSTR	lpPath,
-	LPCSTR	lpFileName,
-	LPCSTR	lpExtension,
-	DWORD	nBufferLength,
-	LPSTR	lpBuffer,
-	LPSTR	*lpFilePart
-	)
-{
-	UNICODE_STRING PathU;
-	UNICODE_STRING FileNameU;
-	UNICODE_STRING ExtensionU;
-	UNICODE_STRING BufferU;
-	ANSI_STRING Path;
-	ANSI_STRING FileName;
-	ANSI_STRING Extension;
-	ANSI_STRING Buffer;
-	PWCHAR FilePartW;
-	DWORD RetValue;
-
-	RtlInitAnsiString (&Path,
-	                   (LPSTR)lpPath);
-	RtlInitAnsiString (&FileName,
-	                   (LPSTR)lpFileName);
-	RtlInitAnsiString (&Extension,
-	                   (LPSTR)lpExtension);
-
-	/* convert ansi (or oem) strings to unicode */
-	if (bIsFileApiAnsi)
-	{
-		RtlAnsiStringToUnicodeString (&PathU,
-		                              &Path,
-		                              TRUE);
-		RtlAnsiStringToUnicodeString (&FileNameU,
-		                              &FileName,
-		                              TRUE);
-		RtlAnsiStringToUnicodeString (&ExtensionU,
-		                              &Extension,
-		                              TRUE);
-	}
-	else
-	{
-		RtlOemStringToUnicodeString (&PathU,
-		                             &Path,
-		                             TRUE);
-		RtlOemStringToUnicodeString (&FileNameU,
-		                             &FileName,
-		                             TRUE);
-		RtlOemStringToUnicodeString (&ExtensionU,
-		                             &Extension,
-		                             TRUE);
-	}
-
-	BufferU.Length = 0;
-	BufferU.MaximumLength = nBufferLength * sizeof(WCHAR);
-	BufferU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
-	                                  0,
-	                                  BufferU.MaximumLength);
-
-	Buffer.Length = 0;
-	Buffer.MaximumLength = nBufferLength;
-	Buffer.Buffer = lpBuffer;
-
-	RetValue = SearchPathW (NULL == lpPath ? NULL : PathU.Buffer,
-	                        NULL == lpFileName ? NULL : FileNameU.Buffer,
-	                        NULL == lpExtension ? NULL : ExtensionU.Buffer,
-	                        nBufferLength,
-	                        BufferU.Buffer,
-	                        &FilePartW);
-
-	RtlFreeHeap (RtlGetProcessHeap (),
-	             0,
-	             PathU.Buffer);
-	RtlFreeHeap (RtlGetProcessHeap (),
-	             0,
-	             FileNameU.Buffer);
-	RtlFreeHeap (RtlGetProcessHeap (),
-	             0,
-	             ExtensionU.Buffer);
-
-	if (0 != RetValue)
-	{
-		BufferU.Length = wcslen(BufferU.Buffer) * sizeof(WCHAR);
-		/* convert ansi (or oem) string to unicode */
-		if (bIsFileApiAnsi)
-			RtlUnicodeStringToAnsiString (&Buffer,
-			                              &BufferU,
-			                              FALSE);
-		else
-			RtlUnicodeStringToOemString (&Buffer,
-			                             &BufferU,
-			                             FALSE);
-		/* nul-terminate ascii string */
-		Buffer.Buffer[BufferU.Length / sizeof(WCHAR)] = '\0';
-	}
-
-	RtlFreeHeap (RtlGetProcessHeap (),
-	             0,
-	             BufferU.Buffer);
-
-	if (NULL != lpFilePart)
-	{
-		*lpFilePart = strrchr (lpBuffer, '\\') + 1;
-	}
+        LPCSTR  lpPath,
+        LPCSTR  lpFileName,
+        LPCSTR  lpExtension,
+        DWORD   nBufferLength,
+        LPSTR   lpBuffer,
+        LPSTR   *lpFilePart
+        )
+{
+        UNICODE_STRING PathU;
+        UNICODE_STRING FileNameU;
+        UNICODE_STRING ExtensionU;
+        UNICODE_STRING BufferU;
+        ANSI_STRING Path;
+        ANSI_STRING FileName;
+        ANSI_STRING Extension;
+        ANSI_STRING Buffer;
+        PWCHAR FilePartW;
+        DWORD RetValue;
+
+        RtlInitAnsiString (&Path,
+                           (LPSTR)lpPath);
+        RtlInitAnsiString (&FileName,
+                           (LPSTR)lpFileName);
+        RtlInitAnsiString (&Extension,
+                           (LPSTR)lpExtension);
+
+        /* convert ansi (or oem) strings to unicode */
+        if (bIsFileApiAnsi)
+        {
+                RtlAnsiStringToUnicodeString (&PathU,
+                                              &Path,
+                                              TRUE);
+                RtlAnsiStringToUnicodeString (&FileNameU,
+                                              &FileName,
+                                              TRUE);
+                RtlAnsiStringToUnicodeString (&ExtensionU,
+                                              &Extension,
+                                              TRUE);
+        }
+        else
+        {
+                RtlOemStringToUnicodeString (&PathU,
+                                             &Path,
+                                             TRUE);
+                RtlOemStringToUnicodeString (&FileNameU,
+                                             &FileName,
+                                             TRUE);
+                RtlOemStringToUnicodeString (&ExtensionU,
+                                             &Extension,
+                                             TRUE);
+        }
+
+        BufferU.Length = 0;
+        BufferU.MaximumLength = nBufferLength * sizeof(WCHAR);
+        BufferU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
+                                          0,
+                                          BufferU.MaximumLength);
+
+        Buffer.Length = 0;
+        Buffer.MaximumLength = nBufferLength;
+        Buffer.Buffer = lpBuffer;
+
+        RetValue = SearchPathW (NULL == lpPath ? NULL : PathU.Buffer,
+                                NULL == lpFileName ? NULL : FileNameU.Buffer,
+                                NULL == lpExtension ? NULL : ExtensionU.Buffer,
+                                nBufferLength,
+                                BufferU.Buffer,
+                                &FilePartW);
+
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     PathU.Buffer);
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     FileNameU.Buffer);
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     ExtensionU.Buffer);
+
+        if (0 != RetValue)
+        {
+                BufferU.Length = wcslen(BufferU.Buffer) * sizeof(WCHAR);
+                /* convert ansi (or oem) string to unicode */
+                if (bIsFileApiAnsi)
+                        RtlUnicodeStringToAnsiString (&Buffer,
+                                                      &BufferU,
+                                                      FALSE);
+                else
+                        RtlUnicodeStringToOemString (&Buffer,
+                                                     &BufferU,
+                                                     FALSE);
+                /* nul-terminate ascii string */
+                Buffer.Buffer[BufferU.Length / sizeof(WCHAR)] = '\0';
+        }
+
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     BufferU.Buffer);
+
+        if (NULL != lpFilePart)
+        {
+                *lpFilePart = strrchr (lpBuffer, '\\') + 1;
+        }
 
-	return RetValue;
+        return RetValue;
 }
 
 
@@ -593,13 +593,13 @@
 DWORD
 STDCALL
 SearchPathW (
-	LPCWSTR	lpPath,
-	LPCWSTR	lpFileName,
[truncated at 1000 lines; 162 more skipped]

reactos/lib/ntdll/ldr
utils.c 1.86 -> 1.87
diff -u -r1.86 -r1.87
--- utils.c	13 May 2004 20:30:26 -0000	1.86
+++ utils.c	2 Jun 2004 18:26:58 -0000	1.87
@@ -1,4 +1,4 @@
-/* $Id: utils.c,v 1.86 2004/05/13 20:30:26 navaraf Exp $
+/* $Id: utils.c,v 1.87 2004/06/02 18:26:58 gvg Exp $
  * 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -59,10 +59,10 @@
 static NTSTATUS LdrFindEntryForName(PUNICODE_STRING Name, PLDR_MODULE *Module, BOOL Ref);
 static PVOID LdrFixupForward(PCHAR ForwardName);
 static PVOID LdrGetExportByName(PVOID BaseAddress, PUCHAR SymbolName, USHORT Hint);
-static NTSTATUS LdrpLoadModule(IN PWSTR SearchPath OPTIONAL, 
-			       IN ULONG LoadFlags,  
-			       IN PUNICODE_STRING Name,
-			       OUT PLDR_MODULE *Module);
+static NTSTATUS LdrpLoadModule(IN PWSTR SearchPath OPTIONAL,
+                               IN ULONG LoadFlags,
+                               IN PUNICODE_STRING Name,
+                               OUT PLDR_MODULE *Module);
 static NTSTATUS LdrpAttachProcess(VOID);
 static VOID LdrpDetachProcess(BOOL UnloadAll);
 
@@ -147,12 +147,12 @@
          {
            while (*TlsCallback)
              {
-	       TRACE_LDR("%wZ - Calling tls callback at %x\n",
-	                 &Module->BaseDllName, TlsCallback);
-	       TlsCallback(Module->BaseAddress, dwReason, NULL);
-	       TlsCallback++;
-	     }
-	 }
+               TRACE_LDR("%wZ - Calling tls callback at %x\n",
+                         &Module->BaseDllName, TlsCallback);
+               TlsCallback(Module->BaseAddress, dwReason, NULL);
+               TlsCallback++;
+             }
+         }
      }
 }
 
@@ -181,32 +181,32 @@
      {
        TlsPointers = RtlAllocateHeap(RtlGetProcessHeap(),
                                      0,
-                                     LdrpTlsCount * sizeof(PVOID) + LdrpTlsSize); 
+                                     LdrpTlsCount * sizeof(PVOID) + LdrpTlsSize);
        if (TlsPointers == NULL)
          {
-	   DPRINT1("failed to allocate thread tls data\n");
-	   return STATUS_NO_MEMORY;
-	 }
-       
+           DPRINT1("failed to allocate thread tls data\n");
+           return STATUS_NO_MEMORY;
+         }
+
        TlsData = (PVOID)TlsPointers + LdrpTlsCount * sizeof(PVOID);
        NtCurrentTeb()->ThreadLocalStoragePointer = TlsPointers;
 
        TlsInfo = LdrpTlsArray;
        for (i = 0; i < LdrpTlsCount; i++, TlsInfo++)
          {
-	   TRACE_LDR("Initialize tls data for %wZ\n", &TlsInfo->Module->BaseDllName);
-	   TlsPointers[i] = TlsData;
-	   if (TlsInfo->TlsDataSize)
-	     {
-	       memcpy(TlsData, TlsInfo->StartAddressOfRawData, TlsInfo->TlsDataSize);
-	       TlsData += TlsInfo->TlsDataSize;
-	     }
-	   if (TlsInfo->TlsZeroSize)
-	     {
-	       memset(TlsData, 0, TlsInfo->TlsZeroSize);
-	       TlsData += TlsInfo->TlsZeroSize;
-	     }
-	 }
+           TRACE_LDR("Initialize tls data for %wZ\n", &TlsInfo->Module->BaseDllName);
+           TlsPointers[i] = TlsData;
+           if (TlsInfo->TlsDataSize)
+             {
+               memcpy(TlsData, TlsInfo->StartAddressOfRawData, TlsInfo->TlsDataSize);
+               TlsData += TlsInfo->TlsDataSize;
+             }
+           if (TlsInfo->TlsZeroSize)
+             {
+               memset(TlsData, 0, TlsInfo->TlsZeroSize);
+               TlsData += TlsInfo->TlsZeroSize;
+             }
+         }
      }
    DPRINT("LdrpInitializeTlsForThread() done\n");
    return STATUS_SUCCESS;
@@ -222,57 +222,57 @@
    PTLS_DATA TlsData;
 
    DPRINT("LdrpInitializeTlsForProccess() called for %wZ\n", &ExeModule->BaseDllName);
-   
+
    if (LdrpTlsCount > 0)
      {
        LdrpTlsArray = RtlAllocateHeap(RtlGetProcessHeap(),
                                       0,
-                                      LdrpTlsCount * sizeof(TLS_DATA)); 
+                                      LdrpTlsCount * sizeof(TLS_DATA));
        if (LdrpTlsArray == NULL)
          {
-	   DPRINT1("Failed to allocate global tls data\n");
+           DPRINT1("Failed to allocate global tls data\n");
            return STATUS_NO_MEMORY;
          }
-      
+
        ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
        Entry = ModuleListHead->Flink;
        while (Entry != ModuleListHead)
          {
            Module = CONTAINING_RECORD(Entry, LDR_MODULE, InLoadOrderModuleList);
-	   if (Module->LoadCount == -1 &&
-	       Module->TlsIndex >= 0)
+           if (Module->LoadCount == -1 &&
+               Module->TlsIndex >= 0)
              {
                TlsDirectory = (PIMAGE_TLS_DIRECTORY)
-		                 RtlImageDirectoryEntryToData(Module->BaseAddress,
+                                 RtlImageDirectoryEntryToData(Module->BaseAddress,
                                                               TRUE,
                                                               IMAGE_DIRECTORY_ENTRY_TLS,
                                                               NULL);
                assert(Module->TlsIndex < LdrpTlsCount);
-	       TlsData = &LdrpTlsArray[Module->TlsIndex];
-	       TlsData->StartAddressOfRawData = (PVOID)TlsDirectory->StartAddressOfRawData;
-	       TlsData->TlsDataSize = TlsDirectory->EndAddressOfRawData - TlsDirectory->StartAddressOfRawData;
-	       TlsData->TlsZeroSize = TlsDirectory->SizeOfZeroFill;
-	       TlsData->TlsAddressOfCallBacks = *TlsDirectory->AddressOfCallBacks;
-	       TlsData->Module = Module;
+               TlsData = &LdrpTlsArray[Module->TlsIndex];
+               TlsData->StartAddressOfRawData = (PVOID)TlsDirectory->StartAddressOfRawData;
+               TlsData->TlsDataSize = TlsDirectory->EndAddressOfRawData - TlsDirectory->StartAddressOfRawData;
+               TlsData->TlsZeroSize = TlsDirectory->SizeOfZeroFill;
+               TlsData->TlsAddressOfCallBacks = *TlsDirectory->AddressOfCallBacks;
+               TlsData->Module = Module;
 #if 0
                DbgPrint("TLS directory for %wZ\n", &Module->BaseDllName);
-	       DbgPrint("StartAddressOfRawData: %x\n", TlsDirectory->StartAddressOfRawData);
-	       DbgPrint("EndAddressOfRawData:   %x\n", TlsDirectory->EndAddressOfRawData);
-	       DbgPrint("SizeOfRawData:         %d\n", TlsDirectory->EndAddressOfRawData - TlsDirectory->StartAddressOfRawData);
-	       DbgPrint("AddressOfIndex:        %x\n", TlsDirectory->AddressOfIndex);
-	       DbgPrint("AddressOfCallBacks:    %x (%x)\n", TlsDirectory->AddressOfCallBacks, *TlsDirectory->AddressOfCallBacks);
-	       DbgPrint("SizeOfZeroFill:        %d\n", TlsDirectory->SizeOfZeroFill);
-	       DbgPrint("Characteristics:       %x\n", TlsDirectory->Characteristics);
+               DbgPrint("StartAddressOfRawData: %x\n", TlsDirectory->StartAddressOfRawData);
+               DbgPrint("EndAddressOfRawData:   %x\n", TlsDirectory->EndAddressOfRawData);
+               DbgPrint("SizeOfRawData:         %d\n", TlsDirectory->EndAddressOfRawData - TlsDirectory->StartAddressOfRawData);
+               DbgPrint("AddressOfIndex:        %x\n", TlsDirectory->AddressOfIndex);
+               DbgPrint("AddressOfCallBacks:    %x (%x)\n", TlsDirectory->AddressOfCallBacks, *TlsDirectory->AddressOfCallBacks);
+               DbgPrint("SizeOfZeroFill:        %d\n", TlsDirectory->SizeOfZeroFill);
+               DbgPrint("Characteristics:       %x\n", TlsDirectory->Characteristics);
 #endif
-	       /* 
-	        * FIXME:
-		*   Is this region allways writable ?
-		*/
+               /*
+                * FIXME:
+                *   Is this region allways writable ?
+                */
                *(PULONG)TlsDirectory->AddressOfIndex = Module->TlsIndex;
-	       CHECKPOINT1;
-	     }
-	   Entry = Entry->Flink;
-	}
+               CHECKPOINT1;
+             }
+           Entry = Entry->Flink;
+        }
     }
   DPRINT("LdrpInitializeTlsForProccess() done\n");
   return STATUS_SUCCESS;
@@ -292,15 +292,15 @@
 
   /* Get handle to the 'KnownDlls' directory */
   RtlInitUnicodeString(&Name,
-		       L"\\KnownDlls");
+                       L"\\KnownDlls");
   InitializeObjectAttributes(&ObjectAttributes,
-			     &Name,
-			     OBJ_CASE_INSENSITIVE,
-			     NULL,
-			     NULL);
+                             &Name,
+                             OBJ_CASE_INSENSITIVE,
+                             NULL,
+                             NULL);
   Status = NtOpenDirectoryObject(&LdrpKnownDllsDirHandle,
-				 DIRECTORY_QUERY | DIRECTORY_TRAVERSE,
-				 &ObjectAttributes);
+                                 DIRECTORY_QUERY | DIRECTORY_TRAVERSE,
+                                 &ObjectAttributes);
   if (!NT_SUCCESS(Status))
     {
       DPRINT("NtOpenDirectoryObject() failed (Status %lx)\n", Status);
@@ -312,8 +312,8 @@
   LinkTarget.Length = 0;
   LinkTarget.MaximumLength = MAX_PATH * sizeof(WCHAR);
   LinkTarget.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
-				      0,
-				      MAX_PATH * sizeof(WCHAR));
+                                      0,
+                                      MAX_PATH * sizeof(WCHAR));
   if (LinkTarget.Buffer == NULL)
     {
       NtClose(LdrpKnownDllsDirHandle);
@@ -322,15 +322,15 @@
     }
 
   RtlInitUnicodeString(&Name,
-		       L"KnownDllPath");
+                       L"KnownDllPath");
   InitializeObjectAttributes(&ObjectAttributes,
-			     &Name,
-			     OBJ_CASE_INSENSITIVE | OBJ_OPENLINK,
-			     LdrpKnownDllsDirHandle,
-			     NULL);
+                             &Name,
+                             OBJ_CASE_INSENSITIVE | OBJ_OPENLINK,
+                             LdrpKnownDllsDirHandle,
+                             NULL);
   Status = NtOpenSymbolicLinkObject(&LinkHandle,
-				    SYMBOLIC_LINK_ALL_ACCESS,
-				    &ObjectAttributes);
+                                    SYMBOLIC_LINK_ALL_ACCESS,
+                                    &ObjectAttributes);
   if (!NT_SUCCESS(Status))
     {
       RtlFreeUnicodeString(&LinkTarget);
@@ -340,8 +340,8 @@
     }
 
   Status = NtQuerySymbolicLinkObject(LinkHandle,
-				     &LinkTarget,
-				     &Length);
+                                     &LinkTarget,
+                                     &Length);
   NtClose(LinkHandle);
   if (!NT_SUCCESS(Status))
     {
@@ -351,7 +351,7 @@
     }
 
   RtlCreateUnicodeString(&LdrpKnownDllPath,
-			 LinkTarget.Buffer);
+                         LinkTarget.Buffer);
 
   RtlFreeUnicodeString(&LinkTarget);
 
@@ -441,8 +441,8 @@
 
 PLDR_MODULE
 LdrAddModuleEntry(PVOID ImageBase,
-		  PIMAGE_NT_HEADERS NTHeaders,
-		  PWSTR FullDosName)
+                  PIMAGE_NT_HEADERS NTHeaders,
+                  PWSTR FullDosName)
 {
   PLDR_MODULE Module;
 
@@ -476,7 +476,7 @@
   RtlCreateUnicodeString (&Module->BaseDllName,
                           wcsrchr(FullDosName, L'\\') + 1);
   DPRINT ("BaseDllName %wZ\n", &Module->BaseDllName);
-  
+
   RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
   InsertTailList(&NtCurrentPeb()->Ldr->InLoadOrderModuleList,
                  &Module->InLoadOrderModuleList);
@@ -488,8 +488,8 @@
 
 static NTSTATUS
 LdrpMapKnownDll(IN PUNICODE_STRING DllName,
-		OUT PUNICODE_STRING FullDosName,
-		OUT PHANDLE SectionHandle)
+                OUT PUNICODE_STRING FullDosName,
+                OUT PHANDLE SectionHandle)
 {
   OBJECT_ATTRIBUTES ObjectAttributes;
   NTSTATUS Status;
@@ -505,13 +505,13 @@
   DPRINT("LdrpKnownDllPath '%wZ'\n", &LdrpKnownDllPath);
 
   InitializeObjectAttributes(&ObjectAttributes,
-			     DllName,
-			     OBJ_CASE_INSENSITIVE,
-			     LdrpKnownDllsDirHandle,
-			     NULL);
+                             DllName,
+                             OBJ_CASE_INSENSITIVE,
+                             LdrpKnownDllsDirHandle,
+                             NULL);
   Status = NtOpenSection(SectionHandle,
-			 SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE,
-			 &ObjectAttributes);
+                         SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE,
+                         &ObjectAttributes);
   if (!NT_SUCCESS(Status))
     {
       DPRINT("NtOpenSection() failed for '%wZ' (Status %lx)\n", DllName, Status);
@@ -521,8 +521,8 @@
   FullDosName->Length = LdrpKnownDllPath.Length + DllName->Length + sizeof(WCHAR);
   FullDosName->MaximumLength = FullDosName->Length + sizeof(WCHAR);
   FullDosName->Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
-					0,
-					FullDosName->MaximumLength);
+                                        0,
+                                        FullDosName->MaximumLength);
   if (FullDosName->Buffer == NULL)
     {
       FullDosName->Length = 0;
@@ -544,9 +544,9 @@
 
 static NTSTATUS
 LdrpMapDllImageFile(IN PWSTR SearchPath OPTIONAL,
-		    IN PUNICODE_STRING DllName,
-		    OUT PUNICODE_STRING FullDosName,
-		    OUT PHANDLE SectionHandle)
+                    IN PUNICODE_STRING DllName,
+                    OUT PUNICODE_STRING FullDosName,
+                    OUT PHANDLE SectionHandle)
 {
   WCHAR                 SearchPathBuffer[MAX_PATH];
   WCHAR                 DosName[MAX_PATH];
@@ -559,20 +559,33 @@
   PVOID                 ImageBase;
   ULONG                 ImageSize;
   IO_STATUS_BLOCK       IoStatusBlock;
-  NTSTATUS Status;
+  NTSTATUS              Status;
+  ULONG                 len;
 
   DPRINT("LdrpMapDllImageFile() called\n");
 
   if (SearchPath == NULL)
     {
-      SearchPath = SearchPathBuffer;
-      wcscpy (SearchPathBuffer, SharedUserData->NtSystemRoot);
+      /* get application running path */
+
+      wcscpy (SearchPathBuffer, NtCurrentPeb()->ProcessParameters->ImagePathName.Buffer);
+
+      len = wcslen (SearchPathBuffer);
+
+      while (len && SearchPathBuffer[len - 1] != L'\\')
+           len--;
+
+      if (len) SearchPathBuffer[len-1] = L'\0';
+
+      wcscat (SearchPathBuffer, L";");
+
+      wcscat (SearchPathBuffer, SharedUserData->NtSystemRoot);
       wcscat (SearchPathBuffer, L"\\system32;");
       wcscat (SearchPathBuffer, SharedUserData->NtSystemRoot);
       wcscat (SearchPathBuffer, L";.");
-    }
 
-  DPRINT("SearchPath %S\n", SearchPath);
+      SearchPath = SearchPathBuffer;
+    }
 
   if (RtlDosSearchPath_U (SearchPath,
                           DllName->Buffer,
@@ -582,7 +595,6 @@
                           NULL) == 0)
     return STATUS_DLL_NOT_FOUND;
 
-  DPRINT("DosName %S\n", DosName);
 
   if (!RtlDosPathNameToNtPathName_U (DosName,
                                      &FullNtFileName,
@@ -608,7 +620,7 @@
                       FILE_SYNCHRONOUS_IO_NONALERT);
   if (!NT_SUCCESS(Status))
     {
-      DPRINT1("Dll open of %wZ failed: Status = 0x%08x\n", 
+      DPRINT1("Dll open of %wZ failed: Status = 0x%08x\n",
                &FullNtFileName, Status);
       RtlFreeUnicodeString (&FullNtFileName);
       return Status;
@@ -631,7 +643,7 @@
       return Status;
     }
   /*
-   * Overlay DOS and NT headers structures to the 
+   * Overlay DOS and NT headers structures to the
    * buffer with DLL's header raw data.
    */
   DosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
@@ -645,15 +657,15 @@
     {
       DPRINT("NTDLL format invalid\n");
       NtClose(FileHandle);
-      
+
       return STATUS_UNSUCCESSFUL;
     }
-  
+
   ImageBase = (PVOID) NTHeaders->OptionalHeader.ImageBase;
   ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
-  
+
   DPRINT("ImageBase 0x%08x\n", ImageBase);
-  
+
   /*
    * Create a section for dll.
    */
@@ -673,7 +685,7 @@
     }
 
   RtlCreateUnicodeString(FullDosName,
-			 DosName);
+                         DosName);
 
   return Status;
 }
@@ -778,7 +790,7 @@
           (Address <= (ModulePtr->BaseAddress + ModulePtr->SizeOfImage)))
         {
           *Module = ModulePtr;
-	  RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
+          RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
           return(STATUS_SUCCESS);
         }
 
@@ -810,7 +822,7 @@
 static NTSTATUS
 LdrFindEntryForName(PUNICODE_STRING Name,
                     PLDR_MODULE *Module,
-		    BOOL Ref)
+                    BOOL Ref)
 {
   PLIST_ENTRY ModuleListHead;
   PLIST_ENTRY Entry;
@@ -849,7 +861,7 @@
       ContainsPath = L'\\' == AdjustedName.Buffer[i] ||
                      L'/' == AdjustedName.Buffer[i];
     }
-  
+
   if (LdrpLastModule)
     {
       if ((! ContainsPath &&
@@ -858,12 +870,12 @@
            0 == RtlCompareUnicodeString(&LdrpLastModule->FullDllName, &AdjustedName, TRUE)))
         {
           *Module = LdrpLastModule;
-	  if (Ref && (*Module)->LoadCount != -1)
-	    {
+          if (Ref && (*Module)->LoadCount != -1)
+            {
               (*Module)->LoadCount++;
-	    }
+            }
           RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
-	  RtlFreeUnicodeString(&AdjustedName);
+          RtlFreeUnicodeString(&AdjustedName);
           return(STATUS_SUCCESS);
         }
     }
@@ -879,12 +891,12 @@
            0 == RtlCompareUnicodeString(&ModulePtr->FullDllName, &AdjustedName, TRUE)))
         {
           *Module = LdrpLastModule = ModulePtr;
-	  if (Ref && ModulePtr->LoadCount != -1)
-	    {
+          if (Ref && ModulePtr->LoadCount != -1)
+            {
               ModulePtr->LoadCount++;
             }
           RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
-	  RtlFreeUnicodeString(&AdjustedName);
+          RtlFreeUnicodeString(&AdjustedName);
           return(STATUS_SUCCESS);
         }
 
@@ -933,8 +945,8 @@
                                           NameBuffer);
 
         Status = LdrFindEntryForName (&DllName, &Module, FALSE);
-	/* FIXME:
-	 *   The caller (or the image) is responsible for loading of the dll, where the function is forwarded.
+        /* FIXME:
+         *   The caller (or the image) is responsible for loading of the dll, where the function is forwarded.
          */
         if (!NT_SUCCESS(Status))
           {
@@ -942,11 +954,11 @@
                                  LDRP_PROCESS_CREATION_TIME,
                                  &DllName,
                                  &BaseAddress);
-	     if (NT_SUCCESS(Status))
-	       {
-	         Status = LdrFindEntryForName (&DllName, &Module, FALSE);
-	       }
-	  }
+             if (NT_SUCCESS(Status))
+               {
+                 Status = LdrFindEntryForName (&DllName, &Module, FALSE);
+               }
+          }
         RtlFreeUnicodeString (&DllName);
         if (!NT_SUCCESS(Status))
           {
@@ -955,7 +967,7 @@
           }
 
         DPRINT("BaseAddress: %p\n", Module->BaseAddress);
-        
+
         return LdrGetExportByName(Module->BaseAddress, p+1, -1);
      }
 
@@ -966,7 +978,7 @@
 /**********************************************************************
  * NAME                                                         LOCAL
  *      LdrGetExportByOrdinal
- *      
+ *
  * DESCRIPTION
  *
  * ARGUMENTS
@@ -980,7 +992,7 @@
  */
 static PVOID
 LdrGetExportByOrdinal (
-        PVOID   BaseAddress,	
+        PVOID   BaseAddress,
         ULONG   Ordinal
         )
 {
@@ -1029,7 +1041,7 @@
 /**********************************************************************
  * NAME                                                         LOCAL
  *      LdrGetExportByName
- *      
+ *
  * DESCRIPTION
  *
  * ARGUMENTS
@@ -1039,7 +1051,7 @@
  * REVISIONS
  *
  * NOTE
- *  AddressOfNames and AddressOfNameOrdinals are paralell tables, 
+ *  AddressOfNames and AddressOfNameOrdinals are paralell tables,
  *  both with NumberOfNames entries.
  *
  */
@@ -1058,7 +1070,7 @@
    PVOID                        Function;
    LONG minn, maxn;
    ULONG ExportDirSize;
-   
+
    DPRINT("LdrGetExportByName %x %s %hu\n", BaseAddress, SymbolName, Hint);
 
    ExportDir = (PIMAGE_EXPORT_DIRECTORY)
@@ -1076,7 +1088,7 @@
    //The symbol names may be missing entirely
    if (ExportDir->AddressOfNames == 0)
    {
-      DPRINT("LdrGetExportByName(): symbol names missing entirely\n");  
+      DPRINT("LdrGetExportByName(): symbol names missing entirely\n");
       return NULL;
    }
 
@@ -1089,7 +1101,7 @@
                               ExportDir->AddressOfNameOrdinals);
    ExFunctions = (PDWORD *)RVA(BaseAddress,
                                ExportDir->AddressOfFunctions);
-   
+
    /*
     * Check the hint first
     */
@@ -1105,17 +1117,17 @@
                {
                   DPRINT("Forward: %s\n", (PCHAR)Function);
                   Function = LdrFixupForward((PCHAR)Function);
-		  if (Function == NULL)
-		    {
+                  if (Function == NULL)
+                    {
                       DPRINT1("LdrGetExportByName(): failed to find %s\n",SymbolName);
-		    } 
-		  return Function;
+                    }
+                  return Function;
                }
              if (Function != NULL)
                return Function;
           }
      }
-   
+
    /*
     * Try a binary search first
     */
@@ -1139,11 +1151,11 @@
                {
                   DPRINT("Forward: %s\n", (PCHAR)Function);
                   Function = LdrFixupForward((PCHAR)Function);
-		  if (Function == NULL)
-		    {
+                  if (Function == NULL)
+                    {
                       DPRINT1("LdrGetExportByName(): failed to find %s\n",SymbolName);
-		    } 
-		  return Function;
+                    }
+                  return Function;
                }
              if (Function != NULL)
                return Function;
@@ -1162,7 +1174,7 @@
              minn = mid + 1;
           }
      }
-   
+
    /*
     * Fall back on a linear search
     */
@@ -1180,12 +1192,12 @@
                {
                   DPRINT("Forward: %s\n", (PCHAR)Function);
                   Function = LdrFixupForward((PCHAR)Function);
-	       }
-	     if (Function == NULL)
-	       {
-	         break;
-	       }
-	     return Function;
+               }
+             if (Function == NULL)
+               {
+                 break;
+               }
+             return Function;
           }
      }
    DPRINT1("LdrGetExportByName(): failed to find %s\n",SymbolName);
@@ -1196,10 +1208,10 @@
 /**********************************************************************
  * NAME                                                         LOCAL
  *      LdrPerformRelocations
- *      
+ *
  * DESCRIPTION
  *      Relocate a DLL's memory image.
- *      
+ *
  * ARGUMENTS
  *
  * RETURN VALUE
@@ -1233,7 +1245,7 @@
       return STATUS_UNSUCCESSFUL;
     }
 
-  Sections = 
+  Sections =
     (PIMAGE_SECTION_HEADER)((PVOID)NTHeaders + sizeof(IMAGE_NT_HEADERS));
   MaxExtend = 0;
   for (i = 0; i < NTHeaders->FileHeader.NumberOfSections; i++)
@@ -1241,19 +1253,19 @@
       if (!(Sections[i].Characteristics & IMAGE_SECTION_NOLOAD))
         {
           ULONG Extend;
-          Extend = 
+          Extend =
             (ULONG)(Sections[i].VirtualAddress + Sections[i].Misc.VirtualSize);
           MaxExtend = max(MaxExtend, Extend);
         }
     }
-  
-  RelocationDDir = 
+
+  RelocationDDir =
     &NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
   RelocationRVA = RelocationDDir->VirtualAddress;
 
   if (RelocationRVA)
     {
-      RelocationDir = 
+      RelocationDir =
         (PRELOCATION_DIRECTORY)((PCHAR)ImageBase + RelocationRVA);
 
       while (RelocationDir->SizeOfBlock)
@@ -1261,21 +1273,21 @@
           if (RelocationDir->VirtualAddress > MaxExtend)
             {
               RelocationRVA += RelocationDir->SizeOfBlock;
-              RelocationDir = 
+              RelocationDir =
                 (PRELOCATION_DIRECTORY) (ImageBase + RelocationRVA);
               continue;
             }
 
           Delta32 = (ULONG)(ImageBase - NTHeaders->OptionalHeader.ImageBase);
-          RelocationBlock = 
-            (PRELOCATION_ENTRY) (RelocationRVA + ImageBase + 
-                                 sizeof (RELOCATION_DIRECTORY));          
-          NumberOfEntries = 
+          RelocationBlock =
+            (PRELOCATION_ENTRY) (RelocationRVA + ImageBase +
+                                 sizeof (RELOCATION_DIRECTORY));
+          NumberOfEntries =
             RelocationDir->SizeOfBlock - sizeof (RELOCATION_DIRECTORY);
           NumberOfEntries = NumberOfEntries / sizeof (RELOCATION_ENTRY);
 
           Status = NtProtectVirtualMemory(NtCurrentProcess(),
-                                          ImageBase + 
+                                          ImageBase +
                                           RelocationDir->VirtualAddress,
                                           PAGE_SIZE,
                                           PAGE_READWRITE,
@@ -1288,25 +1300,25 @@
 
           if (RelocationDir->VirtualAddress + PAGE_SIZE < MaxExtend)
             {
-          	  Status = NtProtectVirtualMemory(NtCurrentProcess(),
-          					  ImageBase + 
-          					  RelocationDir->VirtualAddress + PAGE_SIZE,
-          					  PAGE_SIZE,
-          					  PAGE_READWRITE,
-          					  &OldProtect2);
-          	  if (!NT_SUCCESS(Status))
-          	    {
-          	      DPRINT1("Failed to unprotect relocation target (2).\n");
+                  Status = NtProtectVirtualMemory(NtCurrentProcess(),
+                                                  ImageBase +
+                                                  RelocationDir->VirtualAddress + PAGE_SIZE,
+                                                  PAGE_SIZE,
+                                                  PAGE_READWRITE,
+                                                  &OldProtect2);
+                  if (!NT_SUCCESS(Status))
+                    {
+                      DPRINT1("Failed to unprotect relocation target (2).\n");
                   NtProtectVirtualMemory(NtCurrentProcess(),
-                                        ImageBase + 
+                                        ImageBase +
                                         RelocationDir->VirtualAddress,
                                         PAGE_SIZE,
                                         OldProtect,
                                         &OldProtect);
-          	      return(Status);
-          	    }
+                      return(Status);
+                    }
               }
-                
+
           for (i = 0; i < NumberOfEntries; i++)
             {
               Offset = (RelocationBlock[i].TypeOffset & 0xfff);
@@ -1320,35 +1332,35 @@
                 {
                 case TYPE_RELOC_ABSOLUTE:
                   break;
-                  
+
                 case TYPE_RELOC_HIGH:
                   pValue16 = (PUSHORT)Offset;
                   *pValue16 += Delta32 >> 16;
                   break;
-                  
+
                 case TYPE_RELOC_LOW:
                   pValue16 = (PUSHORT)Offset;
                   *pValue16 += Delta32 & 0xffff;
                   break;
-                  
+
                 case TYPE_RELOC_HIGHLOW:
                   pValue32 = (PULONG)Offset;
                   *pValue32 += Delta32;
                   break;
-                          
+
                 case TYPE_RELOC_HIGHADJ:
                   /* FIXME: do the highadjust fixup  */
                   DPRINT("TYPE_RELOC_HIGHADJ fixup not implemented, sorry\n");
                   return(STATUS_UNSUCCESSFUL);
-                  
+
                 default:
                   DPRINT("unexpected fixup type\n");
                   return STATUS_UNSUCCESSFUL;
-                }             
+                }
             }
 
           Status = NtProtectVirtualMemory(NtCurrentProcess(),
-                                          ImageBase + 
+                                          ImageBase +
                                           RelocationDir->VirtualAddress,
                                           PAGE_SIZE,
                                           OldProtect,
@@ -1361,32 +1373,32 @@
 
           if (RelocationDir->VirtualAddress + PAGE_SIZE < MaxExtend)
             {
-          	  Status = NtProtectVirtualMemory(NtCurrentProcess(),
-          					  ImageBase + 
-          					  RelocationDir->VirtualAddress + PAGE_SIZE,
-          					  PAGE_SIZE,
-          					  OldProtect2,
-          					  &OldProtect2);
-          	  if (!NT_SUCCESS(Status))
-          	    {
-          	      DPRINT1("Failed to protect relocation target2.\n");
-          	      return(Status);
-          	    }
+                  Status = NtProtectVirtualMemory(NtCurrentProcess(),
+                                                  ImageBase +
+                                                  RelocationDir->VirtualAddress + PAGE_SIZE,
+                                                  PAGE_SIZE,
+                                                  OldProtect2,
+                                                  &OldProtect2);
+                  if (!NT_SUCCESS(Status))
+                    {
+                      DPRINT1("Failed to protect relocation target2.\n");
+                      return(Status);
+                    }
             }
 
           RelocationRVA += RelocationDir->SizeOfBlock;
-          RelocationDir = 
+          RelocationDir =
             (PRELOCATION_DIRECTORY) (ImageBase + RelocationRVA);
         }
     }
   return STATUS_SUCCESS;
 }
- 
-static NTSTATUS 
+
+static NTSTATUS
 LdrpGetOrLoadModule(PWCHAR SerachPath,
-		    PCHAR Name, 
-		    PLDR_MODULE* Module, 
-		    BOOL Load)
+                    PCHAR Name,
+                    PLDR_MODULE* Module,
+                    BOOL Load)
 {
    UNICODE_STRING DllName;
    NTSTATUS Status;
@@ -1394,18 +1406,18 @@
    DPRINT("LdrpGetOrLoadModule() called for %s\n", Name);
 
    RtlCreateUnicodeStringFromAsciiz (&DllName, Name);
-	   
+
    Status = LdrFindEntryForName (&DllName, Module, Load);
    if (Load && !NT_SUCCESS(Status))
      {
-       Status = LdrpLoadModule(SerachPath, 
-	                       NtCurrentPeb()->Ldr->Initialized ? 0 : LDRP_PROCESS_CREATION_TIME, 
-			       &DllName, 
-			       Module);
+       Status = LdrpLoadModule(SerachPath,
+                               NtCurrentPeb()->Ldr->Initialized ? 0 : LDRP_PROCESS_CREATION_TIME,
+                               &DllName,
+                               Module);
        if (NT_SUCCESS(Status))
          {
-	   Status = LdrFindEntryForName (&DllName, Module, FALSE);
-	 }
+           Status = LdrFindEntryForName (&DllName, Module, FALSE);
+         }
        if (!NT_SUCCESS(Status))
          {
            DPRINT1("failed to load %wZ\n", &DllName);
@@ -1417,8 +1429,8 @@
 
 static NTSTATUS
 LdrpProcessImportDirectoryEntry(
-   PLDR_MODULE Module, 
-   PLDR_MODULE ImportedModule, 
+   PLDR_MODULE Module,
+   PLDR_MODULE ImportedModule,
    PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory)
 {
    NTSTATUS Status;
@@ -1466,7 +1478,7 @@
        DPRINT1("Failed to unprotect IAT.\n");
        return(Status);
      }
- 
+
    /* Walk through function list and fixup addresses. */
    while (*FunctionNameList != 0L)
      {
@@ -1490,7 +1502,7 @@
                DPRINT1("Failed to import %s from %wZ\n", pe_name->Name, &ImportedModule->FullDllName);
                return STATUS_UNSUCCESSFUL;
              }
-	 }
+         }
        ImportAddressList++;
        FunctionNameList++;
      }
@@ -1512,8 +1524,8 @@
 
 static NTSTATUS
 LdrpProcessImportDirectory(
-   PLDR_MODULE Module, 
-   PLDR_MODULE ImportedModule, 
+   PLDR_MODULE Module,
+   PLDR_MODULE ImportedModule,
    PCHAR ImportedName)
 {
    NTSTATUS Status;
@@ -1525,9 +1537,9 @@
 
 
    ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
-                             RtlImageDirectoryEntryToData(Module->BaseAddress, 
-                                                          TRUE, 
-                                                          IMAGE_DIRECTORY_ENTRY_IMPORT, 
+                             RtlImageDirectoryEntryToData(Module->BaseAddress,
+                                                          TRUE,
+                                                          IMAGE_DIRECTORY_ENTRY_IMPORT,
                                                           NULL);
    if (ImportModuleDirectory == NULL)
      {
@@ -1539,13 +1551,13 @@
        Name = (PCHAR)Module->BaseAddress + ImportModuleDirectory->dwRVAModuleName;
        if (0 == _stricmp(Name, ImportedName))
          {
-	   Status = LdrpProcessImportDirectoryEntry(Module,
-	                                            ImportedModule, 
+           Status = LdrpProcessImportDirectoryEntry(Module,
+                                                    ImportedModule,
                                                     ImportModuleDirectory);
-	   if (!NT_SUCCESS(Status))
-	     {
-	       return Status;
-	     }
+           if (!NT_SUCCESS(Status))
+             {
+               return Status;
+             }
          }
        ImportModuleDirectory++;
      }
@@ -1555,10 +1567,10 @@
 }
 
 
-static NTSTATUS 
-LdrpAdjustImportDirectory(PLDR_MODULE Module, 
-			  PLDR_MODULE ImportedModule,
-			  PUCHAR ImportedName)
+static NTSTATUS
+LdrpAdjustImportDirectory(PLDR_MODULE Module,
+                          PLDR_MODULE ImportedModule,
+                          PUCHAR ImportedName)
 {
    PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory;
    NTSTATUS Status;
@@ -1577,10 +1589,10 @@
           Module, &Module->BaseDllName, ImportedModule, &ImportedModule->BaseDllName, ImportedName);
 
    ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
-                              RtlImageDirectoryEntryToData(Module->BaseAddress, 
-			                                   TRUE, 
-							   IMAGE_DIRECTORY_ENTRY_IMPORT, 
-							   NULL);
+                              RtlImageDirectoryEntryToData(Module->BaseAddress,
+                                                           TRUE,
+                                                           IMAGE_DIRECTORY_ENTRY_IMPORT,
+                                                           NULL);
    if (ImportModuleDirectory == NULL)
      {
        return STATUS_UNSUCCESSFUL;
@@ -1624,7 +1636,7 @@
                DPRINT1("Failed to unprotect IAT.\n");
                return(Status);
              }
-         
+
            NTHeaders = RtlImageNtHeader (ImportedModule->BaseAddress);
            Start = (PVOID)NTHeaders->OptionalHeader.ImageBase;
            End = Start + ImportedModule->SizeOfImage;
@@ -1635,8 +1647,8 @@
              {
                if (*ImportAddressList >= Start && *ImportAddressList < End)
[truncated at 1000 lines; 1155 more skipped]
CVSspam 0.2.8