1a0ee6776309c0dc33a6de3758effe227af4bbc6
[reactos.git] / reactos / lib / kernel32 / file / delete.c
1 /* $Id: delete.c,v 1.16 2004/01/23 21:16:03 ekohl Exp $
2 *
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)
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 /* INCLUDES ****************************************************************/
13
14 #include <k32.h>
15
16 #define NDEBUG
17 #include "../include/debug.h"
18
19
20 /* FUNCTIONS ****************************************************************/
21
22 /*
23 * @implemented
24 */
25 BOOL
26 STDCALL
27 DeleteFileA (
28 LPCSTR lpFileName
29 )
30 {
31 UNICODE_STRING FileNameU;
32 ANSI_STRING FileName;
33 BOOL Result;
34
35 RtlInitAnsiString (&FileName,
36 (LPSTR)lpFileName);
37
38 /* convert ansi (or oem) string to unicode */
39 if (bIsFileApiAnsi)
40 RtlAnsiStringToUnicodeString (&FileNameU,
41 &FileName,
42 TRUE);
43 else
44 RtlOemStringToUnicodeString (&FileNameU,
45 &FileName,
46 TRUE);
47
48 Result = DeleteFileW (FileNameU.Buffer);
49
50 RtlFreeHeap (RtlGetProcessHeap (),
51 0,
52 FileNameU.Buffer);
53
54 return Result;
55 }
56
57
58 /*
59 * @implemented
60 */
61 BOOL
62 STDCALL
63 DeleteFileW (
64 LPCWSTR lpFileName
65 )
66 {
67 FILE_DISPOSITION_INFORMATION FileDispInfo;
68 OBJECT_ATTRIBUTES ObjectAttributes;
69 IO_STATUS_BLOCK IoStatusBlock;
70 UNICODE_STRING NtPathU;
71 HANDLE FileHandle;
72 NTSTATUS Status;
73
74 DPRINT("DeleteFileW (lpFileName %S)\n",lpFileName);
75
76 if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName,
77 &NtPathU,
78 NULL,
79 NULL))
80 return FALSE;
81
82 DPRINT("NtPathU \'%wZ\'\n", &NtPathU);
83
84 ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
85 ObjectAttributes.RootDirectory = NULL;
86 ObjectAttributes.ObjectName = &NtPathU;
87 ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
88 ObjectAttributes.SecurityDescriptor = NULL;
89 ObjectAttributes.SecurityQualityOfService = NULL;
90
91 Status = NtCreateFile (&FileHandle,
92 FILE_WRITE_ATTRIBUTES,
93 &ObjectAttributes,
94 &IoStatusBlock,
95 NULL,
96 FILE_ATTRIBUTE_NORMAL,
97 0,
98 FILE_OPEN,
99 FILE_NON_DIRECTORY_FILE,
100 NULL,
101 0);
102
103 RtlFreeUnicodeString(&NtPathU);
104
105 if (!NT_SUCCESS(Status))
106 {
107 CHECKPOINT;
108 SetLastErrorByStatus (Status);
109 return FALSE;
110 }
111
112 FileDispInfo.DoDeleteFile = TRUE;
113
114 Status = NtSetInformationFile (FileHandle,
115 &IoStatusBlock,
116 &FileDispInfo,
117 sizeof(FILE_DISPOSITION_INFORMATION),
118 FileDispositionInformation);
119 if (!NT_SUCCESS(Status))
120 {
121 CHECKPOINT;
122 NtClose (FileHandle);
123 SetLastErrorByStatus (Status);
124 return FALSE;
125 }
126
127 Status = NtClose (FileHandle);
128 if (!NT_SUCCESS (Status))
129 {
130 CHECKPOINT;
131 SetLastErrorByStatus (Status);
132 return FALSE;
133 }
134
135 return TRUE;
136 }
137
138 /* EOF */