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 ****************************************************************/
17 #include <kernel32/kernel32.h>
20 /* FUNCTIONS ****************************************************************/
28 UNICODE_STRING FileNameU;
32 RtlInitAnsiString (&FileName,
35 /* convert ansi (or oem) string to unicode */
37 RtlAnsiStringToUnicodeString (&FileNameU,
41 RtlOemStringToUnicodeString (&FileNameU,
45 Result = DeleteFileW (FileNameU.Buffer);
47 RtlFreeHeap (RtlGetProcessHeap (),
61 FILE_DISPOSITION_INFORMATION FileDispInfo;
62 OBJECT_ATTRIBUTES ObjectAttributes;
63 IO_STATUS_BLOCK IoStatusBlock;
64 UNICODE_STRING NtPathU;
68 DPRINT("DeleteFileW (lpFileName %S)\n",lpFileName);
70 if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName,
76 DPRINT("NtPathU \'%wZ\'\n", &NtPathU);
78 ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
79 ObjectAttributes.RootDirectory = NULL;
80 ObjectAttributes.ObjectName = &NtPathU;
81 ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
82 ObjectAttributes.SecurityDescriptor = NULL;
83 ObjectAttributes.SecurityQualityOfService = NULL;
85 Status = NtCreateFile (&FileHandle,
86 FILE_WRITE_ATTRIBUTES,
90 FILE_ATTRIBUTE_NORMAL,
93 FILE_NON_DIRECTORY_FILE,
97 RtlFreeUnicodeString(&NtPathU);
99 if (!NT_SUCCESS(Status))
102 SetLastErrorByStatus (Status);
106 FileDispInfo.DoDeleteFile = TRUE;
108 Status = NtSetInformationFile (FileHandle,
111 sizeof(FILE_DISPOSITION_INFORMATION),
112 FileDispositionInformation);
113 if (!NT_SUCCESS(Status))
116 NtClose (FileHandle);
117 SetLastErrorByStatus (Status);
121 Status = NtClose (FileHandle);
122 if (!NT_SUCCESS (Status))
125 SetLastErrorByStatus (Status);