2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
11 #include <sys/types.h>
26 DWORD
ErrnoToLastError(int errno_num
);
28 static int TranslateCreationFlags(DWORD create_flags
);
29 static int TranslateAccessFlags(DWORD access_flags
);
30 static int TranslateShareFlags(DWORD share_flags
);
32 /***********************************************************************
33 * ReadFileEx (KERNEL32.)
37 (CALLBACK
*LPOVERLAPPED_COMPLETION_ROUTINE
)(
39 DWORD dwNumberOfBytesTransfered
,
40 LPOVERLAPPED lpOverlapped
43 BOOL32 WINAPI
ReadFileEx(HFILE32 hFile
, LPVOID lpBuffer
, DWORD numtoread
,
44 LPOVERLAPPED lpOverlapped
,
45 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
48 FIXME(file
, "file %d to buf %p num %ld %p func %p stub\n",
49 hFile
, lpBuffer
, numtoread
, lpOverlapped
, lpCompletionRoutine
);
50 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
55 /*************************************************************************
56 * CreateFile32A [KERNEL32.45] Creates or opens a file or other object
58 * Creates or opens an object, and returns a handle that can be used to
63 * filename [I] pointer to filename to be accessed
64 * access [I] access mode requested
65 * sharing [I] share mode
66 * security [I] pointer to security attributes
69 * template [I] handle to file with attributes to copy
72 * Success: Open handle to specified file
73 * Failure: INVALID_HANDLE_VALUE
76 * Should call SetLastError() on failure.
80 * Doesn't support character devices, pipes, template files, or a
81 * lot of the 'attributes' flags yet.
83 HFILE32 WINAPI
CreateFile32A(LPCSTR filename
, DWORD access
, DWORD sharing
,
84 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
85 DWORD attributes
, HANDLE32
template)
87 int access_flags
, create_flags
, share_flags
;
88 HFILE32 to_dup
= HFILE_ERROR32
; /* handle to dup */
90 /* Translate the various flags to Unix-style.
92 access_flags
= TranslateAccessFlags(access
);
93 create_flags
= TranslateCreationFlags(creation
);
94 share_flags
= TranslateShareFlags(sharing
);
97 FIXME(file
, "template handles not supported.\n");
100 return HFILE_ERROR32
;
101 /* If the name starts with '\\?\' or '\\.\', ignore the first 4 chars.
103 if(!strncmp(filename
, "\\\\?\\", 4) || !strncmp(filename
, "\\\\.\\", 4))
105 if (filename
[2] == '.')
106 return DEVICE_Open( filename
+4, access_flags
| create_flags
);
109 if (!strncmp(filename
, "UNC", 3))
111 FIXME(file
, "UNC name (%s) not supported.\n",filename
);
112 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
113 return HFILE_ERROR32
;
117 /* If the name still starts with '\\', it's a UNC name.
119 if(!strncmp(filename
, "\\\\", 2))
121 FIXME(file
, "UNC names not supported.\n");
122 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
123 return HFILE_ERROR32
;
126 /* If the name is either CONIN$ or CONOUT$, give them duplicated stdin
127 * or stdout, respectively. The lower case version is also allowed. Most likely
128 * this should be a case ignore string compare.
130 if(!strcasecmp(filename
, "CONIN$"))
131 to_dup
= GetStdHandle( STD_INPUT_HANDLE
);
132 else if(!strcasecmp(filename
, "CONOUT$"))
133 to_dup
= GetStdHandle( STD_OUTPUT_HANDLE
);
135 if(to_dup
!= HFILE_ERROR32
)
138 if (!DuplicateHandle( GetCurrentProcess(), to_dup
, GetCurrentProcess(),
139 &handle
, access
, FALSE
, 0 ))
140 handle
= HFILE_ERROR32
;
143 return FILE_Open( filename
, access_flags
| create_flags
,share_flags
);
147 /*************************************************************************
148 * CreateFile32W (KERNEL32.48)
150 HFILE32 WINAPI
CreateFile32W(LPCWSTR filename
, DWORD access
, DWORD sharing
,
151 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
152 DWORD attributes
, HANDLE32
template)
154 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
155 HFILE32 res
= CreateFile32A( afn
, access
, sharing
, security
, creation
,
156 attributes
, template );
157 HeapFree( GetProcessHeap(), 0, afn
);
161 static int TranslateAccessFlags(DWORD access_flags
)
175 case (GENERIC_READ
| GENERIC_WRITE
):
183 static int TranslateCreationFlags(DWORD create_flags
)
190 rc
= O_CREAT
| O_EXCL
;
194 rc
= O_CREAT
| O_TRUNC
;
205 case TRUNCATE_EXISTING
:
212 static int TranslateShareFlags(DWORD share_flags
)
214 OPEN_SHARE_DENYNONE FILE_SHARE_READ | FILE_SHARE_WRITE
215 OPEN_SHARE_DENYREAD FILE_SHARE_WRITE
216 OPEN_SHARE_DENYREADWRITE 0
217 OPEN_SHARE_DENYWRITE FILE_SHARE_READ
222 case FILE_SHARE_READ
| FILE_SHARE_WRITE
:
223 return OF_SHARE_DENY_NONE
;
224 case FILE_SHARE_WRITE
:
225 return OF_SHARE_DENY_READ
;
226 case FILE_SHARE_READ
:
227 return OF_SHARE_DENY_WRITE
;
229 return OF_SHARE_EXCLUSIVE
;
232 FIXME(file
,"unknown sharing flags 0x%04lx\n",share_flags
);
233 return OF_SHARE_EXCLUSIVE
;
235 /**************************************************************************
236 * SetFileAttributes16 (KERNEL.421)
238 BOOL16 WINAPI
SetFileAttributes16( LPCSTR lpFileName
, DWORD attributes
)
240 return SetFileAttributes32A( lpFileName
, attributes
);
244 /**************************************************************************
245 * SetFileAttributes32A (KERNEL32.490)
247 BOOL32 WINAPI
SetFileAttributes32A(LPCSTR lpFileName
, DWORD attributes
)
250 DOS_FULL_NAME full_name
;
252 if (!DOSFS_GetFullName( lpFileName
, TRUE
, &full_name
))
255 TRACE(file
,"(%s,%lx)\n",lpFileName
,attributes
);
256 if (attributes
& FILE_ATTRIBUTE_NORMAL
) {
257 attributes
&= ~FILE_ATTRIBUTE_NORMAL
;
259 FIXME(file
,"(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
260 lpFileName
,attributes
);
262 if(stat(full_name
.long_name
,&buf
)==-1)
264 SetLastError(ErrnoToLastError(errno
));
267 if (attributes
& FILE_ATTRIBUTE_READONLY
)
269 buf
.st_mode
&= ~0222; /* octal!, clear write permission bits */
270 attributes
&= ~FILE_ATTRIBUTE_READONLY
;
272 attributes
&= ~(FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
274 FIXME(file
,"(%s):%lx attribute(s) not implemented.\n",
275 lpFileName
,attributes
);
276 if (-1==chmod(full_name
.long_name
,buf
.st_mode
))
278 SetLastError(ErrnoToLastError(errno
));
285 /**************************************************************************
286 * SetFileAttributes32W (KERNEL32.491)
288 BOOL32 WINAPI
SetFileAttributes32W(LPCWSTR lpFileName
, DWORD attributes
)
290 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName
);
291 BOOL32 res
= SetFileAttributes32A( afn
, attributes
);
292 HeapFree( GetProcessHeap(), 0, afn
);
297 /**************************************************************************
298 * SetFileApisToOEM (KERNEL32.645)
300 VOID WINAPI
SetFileApisToOEM(void)
302 /*FIXME(file,"(): stub!\n");*/
306 /**************************************************************************
307 * SetFileApisToANSI (KERNEL32.644)
309 VOID WINAPI
SetFileApisToANSI(void)
311 /*FIXME(file,"(): stub\n");*/
315 /******************************************************************************
316 * AreFileApisANSI [KERNEL32.105] Determines if file functions are using ANSI
319 * TRUE: Set of file functions is using ANSI code page
320 * FALSE: Set of file functions is using OEM code page
322 BOOL32 WINAPI
AreFileApisANSI(void)
324 FIXME(file
,"(void): stub\n");