1 /* $Id: delete.c,v 1.12 2002/09/08 10:22:41 chorns Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/delete.c
6 * PURPOSE: Deleting files
7 * PROGRAMMER: Ariadne (ariadne@xs4all.nl)
12 /* INCLUDES ****************************************************************/
14 #include <ddk/ntddk.h>
15 #include <ntdll/rtl.h>
19 #include <kernel32/kernel32.h>
20 #include <kernel32/error.h>
23 /* FUNCTIONS ****************************************************************/
31 UNICODE_STRING FileNameU
;
35 RtlInitAnsiString (&FileName
,
38 /* convert ansi (or oem) string to unicode */
40 RtlAnsiStringToUnicodeString (&FileNameU
,
44 RtlOemStringToUnicodeString (&FileNameU
,
48 Result
= DeleteFileW (FileNameU
.Buffer
);
50 RtlFreeHeap (RtlGetProcessHeap (),
64 FILE_DISPOSITION_INFORMATION FileDispInfo
;
65 OBJECT_ATTRIBUTES ObjectAttributes
;
66 IO_STATUS_BLOCK IoStatusBlock
;
67 UNICODE_STRING NtPathU
;
71 DPRINT("DeleteFileW (lpFileName %S)\n",lpFileName
);
73 if (!RtlDosPathNameToNtPathName_U ((LPWSTR
)lpFileName
,
79 DPRINT("NtPathU \'%wZ\'\n", &NtPathU
);
81 ObjectAttributes
.Length
= sizeof(OBJECT_ATTRIBUTES
);
82 ObjectAttributes
.RootDirectory
= NULL
;
83 ObjectAttributes
.ObjectName
= &NtPathU
;
84 ObjectAttributes
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_INHERIT
;
85 ObjectAttributes
.SecurityDescriptor
= NULL
;
86 ObjectAttributes
.SecurityQualityOfService
= NULL
;
88 Status
= NtCreateFile (&FileHandle
,
89 FILE_WRITE_ATTRIBUTES
,
93 FILE_ATTRIBUTE_NORMAL
,
96 FILE_NON_DIRECTORY_FILE
,
100 RtlFreeUnicodeString(&NtPathU
);
102 if (!NT_SUCCESS(Status
))
105 SetLastErrorByStatus (Status
);
109 FileDispInfo
.DoDeleteFile
= TRUE
;
111 Status
= NtSetInformationFile (FileHandle
,
114 sizeof(FILE_DISPOSITION_INFORMATION
),
115 FileDispositionInformation
);
116 if (!NT_SUCCESS(Status
))
119 NtClose (FileHandle
);
120 SetLastErrorByStatus (Status
);
124 Status
= NtClose (FileHandle
);
125 if (!NT_SUCCESS (Status
))
128 SetLastErrorByStatus (Status
);