[ros-diffs] [fireball] 23570: Dmitry Philippov: In MoveFileWithProgressW() - Change alloca() to RtlAllocateHeap() and add missing freeing of the allocated space - Fix incorrect FileNameLength param in call to NtSetInformationFile() - Add support for MOVEFILE_REPLACE_EXISTING flag

fireball at svn.reactos.org fireball at svn.reactos.org
Sun Aug 13 21:49:35 CEST 2006


Author: fireball
Date: Sun Aug 13 23:49:34 2006
New Revision: 23570

URL: http://svn.reactos.org/svn/reactos?rev=23570&view=rev
Log:
Dmitry Philippov: In MoveFileWithProgressW()
    - Change alloca() to RtlAllocateHeap() and add missing freeing of the allocated space
    - Fix incorrect FileNameLength param in call to NtSetInformationFile()
    - Add support for MOVEFILE_REPLACE_EXISTING flag

Modified:
    trunk/reactos/dll/win32/kernel32/file/move.c

Modified: trunk/reactos/dll/win32/kernel32/file/move.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/file/move.c?rev=23570&r1=23569&r2=23570&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/file/move.c (original)
+++ trunk/reactos/dll/win32/kernel32/file/move.c Sun Aug 13 23:49:34 2006
@@ -274,7 +274,15 @@
            return FALSE;
         }
 
-	FileRename = alloca(sizeof(FILE_RENAME_INFORMATION) + DstPathU.Length);
+	FileRename = RtlAllocateHeap(
+		RtlGetProcessHeap(),
+		HEAP_ZERO_MEMORY,
+		sizeof(FILE_RENAME_INFORMATION) + DstPathU.Length);
+	if( !FileRename ) {
+		CloseHandle(hFile);
+		SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+		return FALSE;
+	}
 	if( dwFlags & MOVEFILE_REPLACE_EXISTING ) {
 		FileRename->ReplaceIfExists = TRUE;
 	}
@@ -287,17 +295,15 @@
         RtlFreeHeap (RtlGetProcessHeap (),
 		     0,
 		     DstPathU.Buffer);
-	/*
-	 * FIXME:
-	 *   Is the length the count of characters or the length of the buffer?
-	 */
-	FileRename->FileNameLength = DstPathU.Length / sizeof(WCHAR);
+
+	FileRename->FileNameLength = DstPathU.Length;
 	errCode = NtSetInformationFile (hFile,
 	                                &IoStatusBlock,
 	                                FileRename,
 	                                sizeof(FILE_RENAME_INFORMATION) + DstPathU.Length,
 	                                FileRenameInformation);
 	CloseHandle(hFile);
+	RtlFreeHeap(RtlGetProcessHeap(), 0, FileRename);
 
 	if (GetFileAttributesW(lpExistingFileName) & FILE_ATTRIBUTE_DIRECTORY)
 	{
@@ -325,12 +331,12 @@
 		                      lpProgressRoutine,
 		                      lpData,
 		                      NULL,
-		                      FileRename->ReplaceIfExists ? 0 : COPY_FILE_FAIL_IF_EXISTS);
+		                      (dwFlags & MOVEFILE_REPLACE_EXISTING) ? 0 : COPY_FILE_FAIL_IF_EXISTS);
  		    if (Result)
 		    {
 			/* Cleanup the source file */			
 	                Result = DeleteFileW (lpExistingFileName);
-		    } 
+		    }
                   }
 		 else
 		 {




More information about the Ros-diffs mailing list