1 /* $Id: create.c,v 1.21 2000/06/03 14:47:31 ea 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>
22 #include <kernel32/error.h>
25 /* FUNCTIONS ****************************************************************/
27 HANDLE STDCALL
CreateFileA (LPCSTR lpFileName
,
28 DWORD dwDesiredAccess
,
30 LPSECURITY_ATTRIBUTES lpSecurityAttributes
,
31 DWORD dwCreationDisposition
,
32 DWORD dwFlagsAndAttributes
,
35 UNICODE_STRING FileNameU
;
39 DPRINT("CreateFileA(lpFileName %s)\n",lpFileName
);
41 RtlInitAnsiString (&FileName
,
44 /* convert ansi (or oem) string to unicode */
46 RtlAnsiStringToUnicodeString (&FileNameU
,
50 RtlOemStringToUnicodeString (&FileNameU
,
54 FileHandle
= CreateFileW (FileNameU
.Buffer
,
58 dwCreationDisposition
,
62 RtlFreeHeap (RtlGetProcessHeap (),
70 HANDLE STDCALL
CreateFileW (LPCWSTR lpFileName
,
71 DWORD dwDesiredAccess
,
73 LPSECURITY_ATTRIBUTES lpSecurityAttributes
,
74 DWORD dwCreationDisposition
,
75 DWORD dwFlagsAndAttributes
,
78 OBJECT_ATTRIBUTES ObjectAttributes
;
79 IO_STATUS_BLOCK IoStatusBlock
;
80 UNICODE_STRING NtPathU
;
85 switch (dwCreationDisposition
)
88 dwCreationDisposition
= FILE_CREATE
;
92 dwCreationDisposition
= FILE_OVERWRITE_IF
;
96 dwCreationDisposition
= FILE_OPEN
;
100 dwCreationDisposition
= OPEN_ALWAYS
;
103 case TRUNCATE_EXISTING
:
104 dwCreationDisposition
= FILE_OVERWRITE
;
107 DPRINT("CreateFileW(lpFileName %S)\n",lpFileName
);
109 if (dwDesiredAccess
& GENERIC_READ
)
110 dwDesiredAccess
|= FILE_GENERIC_READ
;
112 if (dwDesiredAccess
& GENERIC_WRITE
)
113 dwDesiredAccess
|= FILE_GENERIC_WRITE
;
115 if (!(dwFlagsAndAttributes
& FILE_FLAG_OVERLAPPED
))
117 Flags
|= FILE_SYNCHRONOUS_IO_ALERT
;
120 if (!RtlDosPathNameToNtPathName_U ((LPWSTR
)lpFileName
,
126 DPRINT("NtPathU \'%S\'\n", NtPathU
.Buffer
);
128 ObjectAttributes
.Length
= sizeof(OBJECT_ATTRIBUTES
);
129 ObjectAttributes
.RootDirectory
= NULL
;
130 ObjectAttributes
.ObjectName
= &NtPathU
;
131 ObjectAttributes
.Attributes
= OBJ_CASE_INSENSITIVE
;
132 ObjectAttributes
.SecurityDescriptor
= NULL
;
133 ObjectAttributes
.SecurityQualityOfService
= NULL
;
135 Status
= NtCreateFile (&FileHandle
,
140 dwFlagsAndAttributes
,
142 dwCreationDisposition
,
146 if (!NT_SUCCESS(Status
))
148 SetLastErrorByStatus (Status
);
149 return INVALID_HANDLE_VALUE
;