Sync with trunk (r48545)
[reactos.git] / dll / win32 / kernel32 / file / delete.c
1 /* $Id$
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 #define NDEBUG
16 #include <reactos/debug.h>
17 static ULONG gDebugChannel = kernel32file;
18
19 /* FUNCTIONS ****************************************************************/
20
21 /*
22 * @implemented
23 */
24 BOOL
25 WINAPI
26 DeleteFileA (
27 LPCSTR lpFileName
28 )
29 {
30 PWCHAR FileNameW;
31
32 if (!(FileNameW = FilenameA2W(lpFileName, FALSE)))
33 return FALSE;
34
35 return DeleteFileW (FileNameW);
36 }
37
38
39 /*
40 * @implemented
41 */
42 BOOL
43 WINAPI
44 DeleteFileW (
45 LPCWSTR lpFileName
46 )
47 {
48 FILE_DISPOSITION_INFORMATION FileDispInfo;
49 OBJECT_ATTRIBUTES ObjectAttributes;
50 IO_STATUS_BLOCK IoStatusBlock;
51 UNICODE_STRING NtPathU;
52 HANDLE FileHandle;
53 NTSTATUS Status;
54
55 TRACE("DeleteFileW (lpFileName %S)\n",lpFileName);
56
57 if (!RtlDosPathNameToNtPathName_U (lpFileName,
58 &NtPathU,
59 NULL,
60 NULL))
61 {
62 SetLastError(ERROR_PATH_NOT_FOUND);
63 return FALSE;
64 }
65
66 TRACE("NtPathU \'%wZ\'\n", &NtPathU);
67
68 InitializeObjectAttributes(&ObjectAttributes,
69 &NtPathU,
70 OBJ_CASE_INSENSITIVE,
71 NULL,
72 NULL);
73
74 Status = NtCreateFile (&FileHandle,
75 DELETE,
76 &ObjectAttributes,
77 &IoStatusBlock,
78 NULL,
79 FILE_ATTRIBUTE_NORMAL,
80 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
81 FILE_OPEN,
82 FILE_NON_DIRECTORY_FILE,
83 NULL,
84 0);
85
86 RtlFreeHeap(RtlGetProcessHeap(),
87 0,
88 NtPathU.Buffer);
89
90 if (!NT_SUCCESS(Status))
91 {
92 WARN("Status 0x%08x\n", Status);
93 SetLastErrorByStatus (Status);
94 return FALSE;
95 }
96
97 FileDispInfo.DeleteFile = TRUE;
98
99 Status = NtSetInformationFile (FileHandle,
100 &IoStatusBlock,
101 &FileDispInfo,
102 sizeof(FILE_DISPOSITION_INFORMATION),
103 FileDispositionInformation);
104 if (!NT_SUCCESS(Status))
105 {
106 WARN("Status 0x%08x\n", Status);
107 NtClose (FileHandle);
108 SetLastErrorByStatus (Status);
109 return FALSE;
110 }
111
112 Status = NtClose (FileHandle);
113 if (!NT_SUCCESS (Status))
114 {
115 WARN("Status 0x%08x\n", Status);
116 SetLastErrorByStatus (Status);
117 return FALSE;
118 }
119
120 return TRUE;
121 }
122
123 /* EOF */