Cleaned up system libraries
[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: Directory 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
13 #undef WIN32_LEAN_AND_MEAN
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 HANDLE STDCALL CreateFileA(LPCSTR lpFileName,
22 DWORD dwDesiredAccess,
23 DWORD dwShareMode,
24 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
25 DWORD dwCreationDisposition,
26 DWORD dwFlagsAndAttributes,
27 HANDLE hTemplateFile)
28 {
29
30 WCHAR FileNameW[MAX_PATH];
31 ULONG i = 0;
32
33 OutputDebugStringA("CreateFileA\n");
34
35 while ((*lpFileName)!=0 && i < MAX_PATH)
36 {
37 FileNameW[i] = *lpFileName;
38 lpFileName++;
39 i++;
40 }
41 FileNameW[i] = 0;
42
43 return CreateFileW(FileNameW,dwDesiredAccess,
44 dwShareMode,
45 lpSecurityAttributes,
46 dwCreationDisposition,
47 dwFlagsAndAttributes,
48 hTemplateFile);
49 }
50
51
52 HANDLE STDCALL CreateFileW(LPCWSTR lpFileName,
53 DWORD dwDesiredAccess,
54 DWORD dwShareMode,
55 LPSECURITY_ATTRIBUTES lpSecurityAttributes,
56 DWORD dwCreationDisposition,
57 DWORD dwFlagsAndAttributes,
58 HANDLE hTemplateFile)
59 {
60 HANDLE FileHandle;
61 NTSTATUS Status;
62
63 OBJECT_ATTRIBUTES ObjectAttributes;
64 IO_STATUS_BLOCK IoStatusBlock;
65 UNICODE_STRING FileNameString;
66 ULONG Flags = 0;
67 WCHAR PathNameW[MAX_PATH];
68 WCHAR *FilePart;
69 UINT Len = 0;
70 WCHAR CurrentDir[MAX_PATH];
71
72 OutputDebugStringA("CreateFileW\n");
73
74 if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED))
75 {
76 Flags |= FILE_SYNCHRONOUS_IO_ALERT;
77 }
78
79 // lstrcpyW(PathNameW,L"\\??\\");
80 PathNameW[0] = '\\';
81 PathNameW[1] = '?';
82 PathNameW[2] = '?';
83 PathNameW[3] = '\\';
84 PathNameW[4] = 0;
85
86 dprintf("Name %w\n",PathNameW);
87 if (lpFileName[0] != L'\\' && lpFileName[1] != L':')
88 {
89 Len = GetCurrentDirectoryW(MAX_PATH,CurrentDir);
90 dprintf("CurrentDir %w\n",CurrentDir);
91 lstrcatW(PathNameW,CurrentDir);
92 dprintf("Name %w\n",PathNameW);
93 }
94 lstrcatW(PathNameW,lpFileName);
95 dprintf("Name %w\n",PathNameW);
96
97 FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR);
98
99 if ( FileNameString.Length == 0 )
100 return NULL;
101
102 if ( FileNameString.Length > MAX_PATH )
103 return NULL;
104
105 FileNameString.Buffer = (WCHAR *)PathNameW;
106 FileNameString.MaximumLength = FileNameString.Length;
107
108 ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
109 ObjectAttributes.RootDirectory = NULL;
110 ObjectAttributes.ObjectName = &FileNameString;
111 ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE;
112 ObjectAttributes.SecurityDescriptor = NULL;
113 ObjectAttributes.SecurityQualityOfService = NULL;
114
115 Status = NtCreateFile(&FileHandle,
116 dwDesiredAccess,
117 &ObjectAttributes,
118 &IoStatusBlock,
119 NULL,
120 dwFlagsAndAttributes,
121 dwShareMode,
122 dwCreationDisposition,
123 Flags,
124 NULL,
125 0);
126 return(FileHandle);
127 }
128