Fixed DeleteFileW().

svn path=/trunk/; revision=573
This commit is contained in:
Eric Kohl 1999-06-27 23:08:31 +00:00
parent bcb831f3c9
commit bd4786ea76

View file

@ -15,9 +15,13 @@
#include <wchar.h>
#include <string.h>
//#define NDEBUG
#define NDEBUG
#include <kernel32/kernel32.h>
/* EXTERNS ******************************************************************/
DWORD STDCALL GetCurrentDriveW(DWORD nBufferLength, PWSTR lpBuffer);
/* FUNCTIONS ****************************************************************/
WINBOOL STDCALL DeleteFileA(LPCSTR lpFileName)
@ -42,31 +46,60 @@ WINBOOL STDCALL DeleteFileW(LPCWSTR lpFileName)
UNICODE_STRING FileNameString;
NTSTATUS errCode;
WCHAR PathNameW[MAX_PATH];
WCHAR FileNameW[MAX_PATH];
HANDLE FileHandle;
FILE_DISPOSITION_INFORMATION FileDispInfo;
IO_STATUS_BLOCK IoStatusBlock;
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);
if ( Len == 0 )
return FALSE;
if ( PathNameW[Len-1] != L'\\' )
{
PathNameW[Len] = L'\\';
PathNameW[Len+1] = 0;
}
return NULL;
if ( PathNameW[Len-1] != L'\\' ) {
PathNameW[Len] = L'\\';
PathNameW[Len+1] = 0;
}
wcscat(PathNameW,lpFileName);
}
else
PathNameW[0] = 0;
lstrcatW(PathNameW,lpFileName);
FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR);
FileNameW[0] = '\\';
FileNameW[1] = '?';
FileNameW[2] = '?';
FileNameW[3] = '\\';
FileNameW[4] = 0;
wcscat(FileNameW,PathNameW);
FileNameString.Length = wcslen( FileNameW)*sizeof(WCHAR);
if ( FileNameString.Length == 0 )
return FALSE;
return NULL;
if (FileNameString.Length > MAX_PATH*sizeof(WCHAR))
return FALSE;
if ( FileNameString.Length > MAX_PATH*sizeof(WCHAR) )
return NULL;
FileNameString.Buffer = (WCHAR *)PathNameW;
FileNameString.MaximumLength = FileNameString.Length+sizeof(WCHAR);
FileNameString.Buffer = (WCHAR *)FileNameW;
FileNameString.MaximumLength = FileNameString.Length + sizeof(WCHAR);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
@ -74,12 +107,52 @@ WINBOOL STDCALL DeleteFileW(LPCWSTR lpFileName)
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = NULL;
ObjectAttributes.SecurityQualityOfService = NULL;
errCode = NtDeleteFile(&ObjectAttributes);
if (!NT_SUCCESS(errCode))
DPRINT("FileName %w\n",FileNameW);
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));
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;
}