mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Fixed DeleteFileW().
svn path=/trunk/; revision=573
This commit is contained in:
parent
bcb831f3c9
commit
bd4786ea76
1 changed files with 93 additions and 20 deletions
|
@ -15,9 +15,13 @@
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
//#define NDEBUG
|
#define NDEBUG
|
||||||
#include <kernel32/kernel32.h>
|
#include <kernel32/kernel32.h>
|
||||||
|
|
||||||
|
/* EXTERNS ******************************************************************/
|
||||||
|
|
||||||
|
DWORD STDCALL GetCurrentDriveW(DWORD nBufferLength, PWSTR lpBuffer);
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
WINBOOL STDCALL DeleteFileA(LPCSTR lpFileName)
|
WINBOOL STDCALL DeleteFileA(LPCSTR lpFileName)
|
||||||
|
@ -42,31 +46,60 @@ WINBOOL STDCALL DeleteFileW(LPCWSTR lpFileName)
|
||||||
UNICODE_STRING FileNameString;
|
UNICODE_STRING FileNameString;
|
||||||
NTSTATUS errCode;
|
NTSTATUS errCode;
|
||||||
WCHAR PathNameW[MAX_PATH];
|
WCHAR PathNameW[MAX_PATH];
|
||||||
|
WCHAR FileNameW[MAX_PATH];
|
||||||
|
HANDLE FileHandle;
|
||||||
|
FILE_DISPOSITION_INFORMATION FileDispInfo;
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
UINT Len;
|
UINT Len;
|
||||||
|
|
||||||
if (lpFileName[1] != ':')
|
DPRINT("DeleteFileW (lpFileName %w)\n",lpFileName);
|
||||||
|
|
||||||
|
if (lpFileName[1] == (WCHAR)':')
|
||||||
|
{
|
||||||
|
wcscpy(PathNameW, lpFileName);
|
||||||
|
}
|
||||||
|
else if (wcslen(lpFileName) > 4 &&
|
||||||
|
lpFileName[0] == (WCHAR)'\\' &&
|
||||||
|
lpFileName[1] == (WCHAR)'\\' &&
|
||||||
|
lpFileName[2] == (WCHAR)'.' &&
|
||||||
|
lpFileName[3] == (WCHAR)'\\')
|
||||||
|
{
|
||||||
|
wcscpy(PathNameW, lpFileName);
|
||||||
|
}
|
||||||
|
else if (lpFileName[0] == (WCHAR)'\\')
|
||||||
|
{
|
||||||
|
GetCurrentDriveW(MAX_PATH,PathNameW);
|
||||||
|
wcscat(PathNameW, lpFileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Len = GetCurrentDirectoryW(MAX_PATH,PathNameW);
|
Len = GetCurrentDirectoryW(MAX_PATH,PathNameW);
|
||||||
if ( Len == 0 )
|
if ( Len == 0 )
|
||||||
return FALSE;
|
return NULL;
|
||||||
if ( PathNameW[Len-1] != L'\\' )
|
if ( PathNameW[Len-1] != L'\\' ) {
|
||||||
{
|
PathNameW[Len] = L'\\';
|
||||||
PathNameW[Len] = L'\\';
|
PathNameW[Len+1] = 0;
|
||||||
PathNameW[Len+1] = 0;
|
}
|
||||||
}
|
wcscat(PathNameW,lpFileName);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
PathNameW[0] = 0;
|
FileNameW[0] = '\\';
|
||||||
lstrcatW(PathNameW,lpFileName);
|
FileNameW[1] = '?';
|
||||||
FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR);
|
FileNameW[2] = '?';
|
||||||
|
FileNameW[3] = '\\';
|
||||||
|
FileNameW[4] = 0;
|
||||||
|
wcscat(FileNameW,PathNameW);
|
||||||
|
|
||||||
|
FileNameString.Length = wcslen( FileNameW)*sizeof(WCHAR);
|
||||||
|
|
||||||
if ( FileNameString.Length == 0 )
|
if ( FileNameString.Length == 0 )
|
||||||
return FALSE;
|
return NULL;
|
||||||
|
|
||||||
if (FileNameString.Length > MAX_PATH*sizeof(WCHAR))
|
if ( FileNameString.Length > MAX_PATH*sizeof(WCHAR) )
|
||||||
return FALSE;
|
return NULL;
|
||||||
|
|
||||||
FileNameString.Buffer = (WCHAR *)PathNameW;
|
FileNameString.Buffer = (WCHAR *)FileNameW;
|
||||||
FileNameString.MaximumLength = FileNameString.Length+sizeof(WCHAR);
|
FileNameString.MaximumLength = FileNameString.Length + sizeof(WCHAR);
|
||||||
|
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
ObjectAttributes.RootDirectory = NULL;
|
ObjectAttributes.RootDirectory = NULL;
|
||||||
|
@ -74,12 +107,52 @@ WINBOOL STDCALL DeleteFileW(LPCWSTR lpFileName)
|
||||||
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
|
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
|
||||||
ObjectAttributes.SecurityDescriptor = NULL;
|
ObjectAttributes.SecurityDescriptor = NULL;
|
||||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||||
|
|
||||||
errCode = NtDeleteFile(&ObjectAttributes);
|
DPRINT("FileName %w\n",FileNameW);
|
||||||
if (!NT_SUCCESS(errCode))
|
|
||||||
|
errCode = ZwCreateFile(&FileHandle,
|
||||||
|
FILE_WRITE_ATTRIBUTES,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
NULL,
|
||||||
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
|
0,
|
||||||
|
FILE_OPEN,
|
||||||
|
FILE_DIRECTORY_FILE,
|
||||||
|
NULL,
|
||||||
|
0);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(errCode))
|
||||||
{
|
{
|
||||||
|
CHECKPOINT;
|
||||||
SetLastError(RtlNtStatusToDosError(errCode));
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileDispInfo.DeleteFile = TRUE;
|
||||||
|
|
||||||
|
errCode = NtSetInformationFile(FileHandle,
|
||||||
|
&IoStatusBlock,
|
||||||
|
&FileDispInfo,
|
||||||
|
sizeof(FILE_DISPOSITION_INFORMATION),
|
||||||
|
FileDispositionInformation);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(errCode))
|
||||||
|
{
|
||||||
|
CHECKPOINT;
|
||||||
|
NtClose(FileHandle);
|
||||||
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
errCode = NtClose(FileHandle);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(errCode))
|
||||||
|
{
|
||||||
|
CHECKPOINT;
|
||||||
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue