2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
11 #include <sys/types.h>
25 DWORD
ErrnoToLastError(int errno_num
);
27 static int TranslateCreationFlags(DWORD create_flags
);
28 static int TranslateAccessFlags(DWORD access_flags
);
30 /***********************************************************************
31 * WriteFile (KERNEL32.578)
33 BOOL32 WINAPI
WriteFile(HANDLE32 hFile
, LPCVOID lpBuffer
,
34 DWORD numberOfBytesToWrite
,
35 LPDWORD numberOfBytesWritten
, LPOVERLAPPED lpOverlapped
)
38 BOOL32 status
= FALSE
;
40 TRACE(file
, "%d %p %ld\n", hFile
, lpBuffer
,
41 numberOfBytesToWrite
);
43 if (!(ioptr
= HANDLE_GetObjPtr( PROCESS_Current(), hFile
,
46 if (K32OBJ_OPS(ioptr
)->write
)
47 status
= K32OBJ_OPS(ioptr
)->write(ioptr
, lpBuffer
, numberOfBytesToWrite
,
48 numberOfBytesWritten
, lpOverlapped
);
49 K32OBJ_DecCount( ioptr
);
53 /***********************************************************************
54 * ReadFile (KERNEL32.428)
56 BOOL32 WINAPI
ReadFile(HANDLE32 hFile
, LPVOID lpBuffer
, DWORD numberOfBytesToRead
,
57 LPDWORD numberOfBytesRead
, LPOVERLAPPED lpOverlapped
)
60 BOOL32 status
= FALSE
;
62 TRACE(file
, "%d %p %ld\n", hFile
, lpBuffer
,
65 if (!(ioptr
= HANDLE_GetObjPtr( PROCESS_Current(), hFile
,
68 if (K32OBJ_OPS(ioptr
)->read
)
69 status
= K32OBJ_OPS(ioptr
)->read(ioptr
, lpBuffer
, numberOfBytesToRead
,
70 numberOfBytesRead
, lpOverlapped
);
71 K32OBJ_DecCount( ioptr
);
76 /***********************************************************************
77 * ReadFileEx (KERNEL32.)
81 (WINAPI
*LPOVERLAPPED_COMPLETION_ROUTINE
)(
83 DWORD dwNumberOfBytesTransfered
,
84 LPOVERLAPPED lpOverlapped
87 BOOL32 WINAPI
ReadFileEx(HFILE32 hFile
, LPVOID lpBuffer
, DWORD numtoread
,
88 LPOVERLAPPED lpOverlapped
,
89 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
92 FIXME(file
, "file %d to buf %p num %ld %p func %p stub\n",
93 hFile
, lpBuffer
, numtoread
, lpOverlapped
, lpCompletionRoutine
);
94 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
99 /*************************************************************************
100 * CreateFile32A (KERNEL32.45)
102 * Doesn't support character devices, pipes, template files, or a
103 * lot of the 'attributes' flags yet.
105 HFILE32 WINAPI
CreateFile32A(LPCSTR filename
, DWORD access
, DWORD sharing
,
106 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
107 DWORD attributes
, HANDLE32
template)
109 int access_flags
, create_flags
;
111 /* Translate the various flags to Unix-style.
113 access_flags
= TranslateAccessFlags(access
);
114 create_flags
= TranslateCreationFlags(creation
);
117 FIXME(file
, "template handles not supported.\n");
119 /* If the name starts with '\\?' or '\\.', ignore the first 3 chars.
121 if(!strncmp(filename
, "\\\\?", 3) || !strncmp(filename
, "\\\\.", 3))
124 /* If the name still starts with '\\', it's a UNC name.
126 if(!strncmp(filename
, "\\\\", 2))
128 FIXME(file
, "UNC names not supported.\n");
129 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
130 return HFILE_ERROR32
;
133 /* If the name is either CONIN$ or CONOUT$, give them stdin
134 * or stdout, respectively.
136 if(!strcmp(filename
, "CONIN$")) return GetStdHandle( STD_INPUT_HANDLE
);
137 if(!strcmp(filename
, "CONOUT$")) return GetStdHandle( STD_OUTPUT_HANDLE
);
139 return FILE_Open( filename
, access_flags
| create_flags
);
143 /*************************************************************************
144 * CreateFile32W (KERNEL32.48)
146 HFILE32 WINAPI
CreateFile32W(LPCWSTR filename
, DWORD access
, DWORD sharing
,
147 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
148 DWORD attributes
, HANDLE32
template)
150 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
151 HFILE32 res
= CreateFile32A( afn
, access
, sharing
, security
, creation
,
152 attributes
, template );
153 HeapFree( GetProcessHeap(), 0, afn
);
157 static int TranslateAccessFlags(DWORD access_flags
)
171 case (GENERIC_READ
| GENERIC_WRITE
):
179 static int TranslateCreationFlags(DWORD create_flags
)
186 rc
= O_CREAT
| O_EXCL
;
190 rc
= O_CREAT
| O_TRUNC
;
201 case TRUNCATE_EXISTING
:
210 /**************************************************************************
211 * SetFileAttributes16 (KERNEL.421)
213 BOOL16 WINAPI
SetFileAttributes16( LPCSTR lpFileName
, DWORD attributes
)
215 return SetFileAttributes32A( lpFileName
, attributes
);
219 /**************************************************************************
220 * SetFileAttributes32A (KERNEL32.490)
222 BOOL32 WINAPI
SetFileAttributes32A(LPCSTR lpFileName
, DWORD attributes
)
225 DOS_FULL_NAME full_name
;
227 if (!DOSFS_GetFullName( lpFileName
, TRUE
, &full_name
))
230 TRACE(file
,"(%s,%lx)\n",lpFileName
,attributes
);
231 if (attributes
& FILE_ATTRIBUTE_NORMAL
) {
232 attributes
&= ~FILE_ATTRIBUTE_NORMAL
;
234 FIXME(file
,"(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
235 lpFileName
,attributes
);
237 if(stat(full_name
.long_name
,&buf
)==-1)
239 SetLastError(ErrnoToLastError(errno
));
242 if (attributes
& FILE_ATTRIBUTE_READONLY
)
244 buf
.st_mode
&= ~0222; /* octal!, clear write permission bits */
245 attributes
&= ~FILE_ATTRIBUTE_READONLY
;
247 attributes
&= ~(FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
249 FIXME(file
,"(%s):%lx attribute(s) not implemented.\n",
250 lpFileName
,attributes
);
251 if (-1==chmod(full_name
.long_name
,buf
.st_mode
))
253 SetLastError(ErrnoToLastError(errno
));
260 /**************************************************************************
261 * SetFileAttributes32W (KERNEL32.491)
263 BOOL32 WINAPI
SetFileAttributes32W(LPCWSTR lpFileName
, DWORD attributes
)
265 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName
);
266 BOOL32 res
= SetFileAttributes32A( afn
, attributes
);
267 HeapFree( GetProcessHeap(), 0, afn
);
272 /**************************************************************************
273 * SetFileApisToOEM (KERNEL32.645)
275 VOID WINAPI
SetFileApisToOEM(void)
277 /*FIXME(file,"(): stub!\n");*/
281 /**************************************************************************
282 * SetFileApisToANSI (KERNEL32.644)
284 VOID WINAPI
SetFileApisToANSI(void)
286 /*FIXME(file,"(): stub\n");*/
290 /******************************************************************************
291 * AreFileApisANSI [KERNEL32.105] Determines if file functions are using ANSI
294 * TRUE: Set of file functions is using ANSI code page
295 * FALSE: Set of file functions is using OEM code page
297 BOOL32 WINAPI
AreFileApisANSI(void)
299 FIXME(file
,"(void): stub\n");