Created bugs in wait and timer code
[reactos.git] / reactos / lib / kernel32 / file / create.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/kernel32/file/create.c
5 * PURPOSE: File create/open functions
6 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
7 * GetTempFileName is modified from WINE [ Alexandre Juiliard ]
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <windows.h>
15 #include <ddk/ntddk.h>
16 #include <wstring.h>
17 #include <string.h>
18 #include <kernel32/li.h>
19 #include <ddk/rtl.h>
20
21 #define NDEBUG
22 #include <kernel32/kernel32.h>
23
24 /* FUNCTIONS ****************************************************************/
25
26 HANDLE STDCALL CreateFileA(LPCSTR lpFileName,
27 DWORD dwDesiredAccess,
28 DWORD dwShareMode,
29 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
30 DWORD dwCreationDisposition,
31 DWORD dwFlagsAndAttributes,
32 HANDLE hTemplateFile)
33 {
34
35 WCHAR FileNameW[MAX_PATH];
36 ULONG i = 0;
37
38 DPRINT("CreateFileA\n");
39
40 while ((*lpFileName)!=0 && i < MAX_PATH)
41 {
42 FileNameW[i] = *lpFileName;
43 lpFileName++;
44 i++;
45 }
46 FileNameW[i] = 0;
47
48 return CreateFileW(FileNameW,dwDesiredAccess,
49 dwShareMode,
50 lpSecurityAttributes,
51 dwCreationDisposition,
52 dwFlagsAndAttributes,
53 hTemplateFile);
54 }
55
56
57 HANDLE STDCALL CreateFileW(LPCWSTR lpFileName,
58 DWORD dwDesiredAccess,
59 DWORD dwShareMode,
60 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
61 DWORD dwCreationDisposition,
62 DWORD dwFlagsAndAttributes,
63 HANDLE hTemplateFile)
64 {
65 HANDLE FileHandle;
66 NTSTATUS Status;
67
68 OBJECT_ATTRIBUTES ObjectAttributes;
69 IO_STATUS_BLOCK IoStatusBlock;
70 UNICODE_STRING FileNameString;
71 ULONG Flags = 0;
72 WCHAR PathNameW[MAX_PATH];
73 WCHAR *FilePart;
74 UINT Len = 0;
75 WCHAR CurrentDir[MAX_PATH];
76
77 DPRINT("CreateFileW\n");
78
79 if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED))
80 {
81 Flags |= FILE_SYNCHRONOUS_IO_ALERT;
82 }
83
84 // lstrcpyW(PathNameW,L"\\??\\");
85 PathNameW[0] = '\\';
86 PathNameW[1] = '?';
87 PathNameW[2] = '?';
88 PathNameW[3] = '\\';
89 PathNameW[4] = 0;
90
91 DPRINT("Name %w\n",PathNameW);
92 if (lpFileName[0] != L'\\' && lpFileName[1] != L':')
93 {
94 Len = GetCurrentDirectoryW(MAX_PATH,CurrentDir);
95 DPRINT("CurrentDir %w\n",CurrentDir);
96 lstrcatW(PathNameW,CurrentDir);
97 DPRINT("Name %w\n",PathNameW);
98 }
99 lstrcatW(PathNameW,lpFileName);
100 DPRINT("Name %w\n",PathNameW);
101
102 FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR);
103
104 if ( FileNameString.Length == 0 )
105 return NULL;
106
107 if ( FileNameString.Length > MAX_PATH )
108 return NULL;
109
110 FileNameString.Buffer = (WCHAR *)PathNameW;
111 FileNameString.MaximumLength = FileNameString.Length;
112
113 ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
114 ObjectAttributes.RootDirectory = NULL;
115 ObjectAttributes.ObjectName = &FileNameString;
116 ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE;
117 ObjectAttributes.SecurityDescriptor = NULL;
118 ObjectAttributes.SecurityQualityOfService = NULL;
119
120 Status = NtCreateFile(&FileHandle,
121 dwDesiredAccess,
122 &ObjectAttributes,
123 &IoStatusBlock,
124 NULL,
125 dwFlagsAndAttributes,
126 dwShareMode,
127 dwCreationDisposition,
128 Flags,
129 NULL,
130 0);
131 return(FileHandle);
132 }
133