1 /* $Id: create.c,v 1.19 2000/03/14 23:09:23 ekohl Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/create.c
6 * PURPOSE: Directory functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * GetTempFileName is modified from WINE [ Alexandre Juiliard ]
11 * Removed use of SearchPath (not used by Windows)
14 /* INCLUDES *****************************************************************/
16 #include <ddk/ntddk.h>
17 #include <ntdll/rtl.h>
21 #include <kernel32/kernel32.h>
24 /* FUNCTIONS ****************************************************************/
30 DWORD dwDesiredAccess
,
32 LPSECURITY_ATTRIBUTES lpSecurityAttributes
,
33 DWORD dwCreationDisposition
,
34 DWORD dwFlagsAndAttributes
,
38 UNICODE_STRING FileNameU
;
42 DPRINT("CreateFileA(lpFileName %s)\n",lpFileName
);
44 RtlInitAnsiString (&FileName
,
47 /* convert ansi (or oem) string to unicode */
49 RtlAnsiStringToUnicodeString (&FileNameU
,
53 RtlOemStringToUnicodeString (&FileNameU
,
57 FileHandle
= CreateFileW (FileNameU
.Buffer
,
61 dwCreationDisposition
,
65 RtlFreeHeap (RtlGetProcessHeap (),
77 DWORD dwDesiredAccess
,
79 LPSECURITY_ATTRIBUTES lpSecurityAttributes
,
80 DWORD dwCreationDisposition
,
81 DWORD dwFlagsAndAttributes
,
85 OBJECT_ATTRIBUTES ObjectAttributes
;
86 IO_STATUS_BLOCK IoStatusBlock
;
87 UNICODE_STRING NtPathU
;
92 switch (dwCreationDisposition
)
95 dwCreationDisposition
= FILE_CREATE
;
99 dwCreationDisposition
= FILE_OVERWRITE_IF
;
103 dwCreationDisposition
= FILE_OPEN
;
107 dwCreationDisposition
= OPEN_ALWAYS
;
110 case TRUNCATE_EXISTING
:
111 dwCreationDisposition
= FILE_OVERWRITE
;
114 DPRINT("CreateFileW(lpFileName %S)\n",lpFileName
);
116 if (dwDesiredAccess
& GENERIC_READ
)
117 dwDesiredAccess
|= FILE_GENERIC_READ
;
119 if (dwDesiredAccess
& GENERIC_WRITE
)
120 dwDesiredAccess
|= FILE_GENERIC_WRITE
;
122 if (!(dwFlagsAndAttributes
& FILE_FLAG_OVERLAPPED
))
124 Flags
|= FILE_SYNCHRONOUS_IO_ALERT
;
127 if (!RtlDosPathNameToNtPathName_U ((LPWSTR
)lpFileName
,
133 DPRINT("NtPathU \'%S\'\n", NtPathU
.Buffer
);
135 ObjectAttributes
.Length
= sizeof(OBJECT_ATTRIBUTES
);
136 ObjectAttributes
.RootDirectory
= NULL
;
137 ObjectAttributes
.ObjectName
= &NtPathU
;
138 ObjectAttributes
.Attributes
= OBJ_CASE_INSENSITIVE
;
139 ObjectAttributes
.SecurityDescriptor
= NULL
;
140 ObjectAttributes
.SecurityQualityOfService
= NULL
;
142 Status
= NtCreateFile (&FileHandle
,
147 dwFlagsAndAttributes
,
149 dwCreationDisposition
,
153 if (!NT_SUCCESS(Status
))
155 SetLastError (RtlNtStatusToDosError (Status
));
156 return INVALID_HANDLE_VALUE
;