From 06a3c3a281f4af6f6d37caf97a9234e183a5338f Mon Sep 17 00:00:00 2001 From: Erich Hoover Date: Tue, 12 Feb 2008 23:02:34 +0100 Subject: [PATCH] kernel32: Implement ReplaceFileA. --- dlls/kernel32/file.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c index 4e05c284211..acc762b3ece 100644 --- a/dlls/kernel32/file.c +++ b/dlls/kernel32/file.c @@ -1542,10 +1542,37 @@ BOOL WINAPI ReplaceFileA(LPCSTR lpReplacedFileName,LPCSTR lpReplacementFileName, LPCSTR lpBackupFileName, DWORD dwReplaceFlags, LPVOID lpExclude, LPVOID lpReserved) { - FIXME("(%s,%s,%s,%08x,%p,%p) stub\n",lpReplacedFileName,lpReplacementFileName, - lpBackupFileName,dwReplaceFlags,lpExclude,lpReserved); - SetLastError(ERROR_UNABLE_TO_MOVE_REPLACEMENT); - return FALSE; + WCHAR *replacedW, *replacementW, *backupW = NULL; + BOOL ret; + + /* This function only makes sense when the first two parameters are defined */ + if (!lpReplacedFileName || !(replacedW = FILE_name_AtoW( lpReplacedFileName, TRUE ))) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + if (!lpReplacementFileName || !(replacementW = FILE_name_AtoW( lpReplacementFileName, TRUE ))) + { + HeapFree( GetProcessHeap(), 0, replacedW ); + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + /* The backup parameter, however, is optional */ + if (lpBackupFileName) + { + if (!(backupW = FILE_name_AtoW( lpBackupFileName, TRUE ))) + { + HeapFree( GetProcessHeap(), 0, replacedW ); + HeapFree( GetProcessHeap(), 0, replacementW ); + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + } + ret = ReplaceFileW( replacedW, replacementW, backupW, dwReplaceFlags, lpExclude, lpReserved ); + HeapFree( GetProcessHeap(), 0, replacedW ); + HeapFree( GetProcessHeap(), 0, replacementW ); + HeapFree( GetProcessHeap(), 0, backupW ); + return ret; }