2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
10 #include <sys/types.h>
24 DWORD
ErrnoToLastError(int errno_num
);
26 static int TranslateCreationFlags(DWORD create_flags
);
27 static int TranslateAccessFlags(DWORD access_flags
);
29 /***********************************************************************
30 * WriteFile (KERNEL32.578)
32 BOOL32 WINAPI
WriteFile(HANDLE32 hFile
, LPCVOID lpBuffer
,
33 DWORD numberOfBytesToWrite
,
34 LPDWORD numberOfBytesWritten
, LPOVERLAPPED lpOverlapped
)
37 BOOL32 status
= FALSE
;
39 TRACE(file
, "%d %p %ld\n", hFile
, lpBuffer
,
40 numberOfBytesToWrite
);
42 if (!(ioptr
= HANDLE_GetObjPtr( PROCESS_Current(), hFile
,
45 if (K32OBJ_OPS(ioptr
)->write
)
46 status
= K32OBJ_OPS(ioptr
)->write(ioptr
, lpBuffer
, numberOfBytesToWrite
,
47 numberOfBytesWritten
, lpOverlapped
);
48 K32OBJ_DecCount( ioptr
);
52 /***********************************************************************
53 * ReadFile (KERNEL32.428)
55 BOOL32 WINAPI
ReadFile(HANDLE32 hFile
, LPVOID lpBuffer
, DWORD numberOfBytesToRead
,
56 LPDWORD numberOfBytesRead
, LPOVERLAPPED lpOverlapped
)
59 BOOL32 status
= FALSE
;
61 TRACE(file
, "%d %p %ld\n", hFile
, lpBuffer
,
64 if (!(ioptr
= HANDLE_GetObjPtr( PROCESS_Current(), hFile
,
67 if (K32OBJ_OPS(ioptr
)->read
)
68 status
= K32OBJ_OPS(ioptr
)->read(ioptr
, lpBuffer
, numberOfBytesToRead
,
69 numberOfBytesRead
, lpOverlapped
);
70 K32OBJ_DecCount( ioptr
);
75 /***********************************************************************
76 * ReadFileEx (KERNEL32.)
80 (WINAPI
*LPOVERLAPPED_COMPLETION_ROUTINE
)(
82 DWORD dwNumberOfBytesTransfered
,
83 LPOVERLAPPED lpOverlapped
86 BOOL32 WINAPI
ReadFileEx(HFILE32 hFile
, LPVOID lpBuffer
, DWORD numtoread
,
87 LPOVERLAPPED lpOverlapped
,
88 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
91 FIXME(file
, "file %d to buf %p num %ld %p func %p stub\n",
92 hFile
, lpBuffer
, numtoread
, lpOverlapped
, lpCompletionRoutine
);
93 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
98 /*************************************************************************
99 * CreateFile32A (KERNEL32.45)
101 * Doesn't support character devices, pipes, template files, or a
102 * lot of the 'attributes' flags yet.
104 HFILE32 WINAPI
CreateFile32A(LPCSTR filename
, DWORD access
, DWORD sharing
,
105 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
106 DWORD attributes
, HANDLE32
template)
108 int access_flags
, create_flags
;
110 /* Translate the various flags to Unix-style.
112 access_flags
= TranslateAccessFlags(access
);
113 create_flags
= TranslateCreationFlags(creation
);
116 FIXME(file
, "template handles not supported.\n");
118 /* If the name starts with '\\?' or '\\.', ignore the first 3 chars.
120 if(!strncmp(filename
, "\\\\?", 3) || !strncmp(filename
, "\\\\.", 3))
123 /* If the name still starts with '\\', it's a UNC name.
125 if(!strncmp(filename
, "\\\\", 2))
127 FIXME(file
, "UNC names not supported.\n");
128 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
129 return HFILE_ERROR32
;
132 /* If the name is either CONIN$ or CONOUT$, give them stdin
133 * or stdout, respectively.
135 if(!strcmp(filename
, "CONIN$")) return GetStdHandle( STD_INPUT_HANDLE
);
136 if(!strcmp(filename
, "CONOUT$")) return GetStdHandle( STD_OUTPUT_HANDLE
);
138 return FILE_Open( filename
, access_flags
| create_flags
);
142 /*************************************************************************
143 * CreateFile32W (KERNEL32.48)
145 HFILE32 WINAPI
CreateFile32W(LPCWSTR filename
, DWORD access
, DWORD sharing
,
146 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
147 DWORD attributes
, HANDLE32
template)
149 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
150 HFILE32 res
= CreateFile32A( afn
, access
, sharing
, security
, creation
,
151 attributes
, template );
152 HeapFree( GetProcessHeap(), 0, afn
);
156 static int TranslateAccessFlags(DWORD access_flags
)
170 case (GENERIC_READ
| GENERIC_WRITE
):
178 static int TranslateCreationFlags(DWORD create_flags
)
185 rc
= O_CREAT
| O_EXCL
;
189 rc
= O_CREAT
| O_TRUNC
;
200 case TRUNCATE_EXISTING
:
209 /**************************************************************************
210 * SetFileAttributes16 (KERNEL.421)
212 BOOL16 WINAPI
SetFileAttributes16( LPCSTR lpFileName
, DWORD attributes
)
214 return SetFileAttributes32A( lpFileName
, attributes
);
218 /**************************************************************************
219 * SetFileAttributes32A (KERNEL32.490)
221 BOOL32 WINAPI
SetFileAttributes32A(LPCSTR lpFileName
, DWORD attributes
)
224 DOS_FULL_NAME full_name
;
226 if (!DOSFS_GetFullName( lpFileName
, TRUE
, &full_name
))
229 TRACE(file
,"(%s,%lx)\n",lpFileName
,attributes
);
230 if (attributes
& FILE_ATTRIBUTE_NORMAL
) {
231 attributes
&= ~FILE_ATTRIBUTE_NORMAL
;
233 FIXME(file
,"(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
234 lpFileName
,attributes
);
236 if(stat(full_name
.long_name
,&buf
)==-1)
238 SetLastError(ErrnoToLastError(errno
));
241 if (attributes
& FILE_ATTRIBUTE_READONLY
)
243 buf
.st_mode
&= ~0222; /* octal!, clear write permission bits */
244 attributes
&= ~FILE_ATTRIBUTE_READONLY
;
246 attributes
&= ~(FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
248 FIXME(file
,"(%s):%lx attribute(s) not implemented.\n",
249 lpFileName
,attributes
);
250 if (-1==chmod(full_name
.long_name
,buf
.st_mode
))
252 SetLastError(ErrnoToLastError(errno
));
259 /**************************************************************************
260 * SetFileAttributes32W (KERNEL32.491)
262 BOOL32 WINAPI
SetFileAttributes32W(LPCWSTR lpFileName
, DWORD attributes
)
264 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName
);
265 BOOL32 res
= SetFileAttributes32A( afn
, attributes
);
266 HeapFree( GetProcessHeap(), 0, afn
);
271 /**************************************************************************
272 * SetFileApisToOEM (KERNEL32.645)
274 VOID WINAPI
SetFileApisToOEM(void)
276 /*FIXME(file,"(): stub!\n");*/
280 /**************************************************************************
281 * SetFileApisToANSI (KERNEL32.644)
283 VOID WINAPI
SetFileApisToANSI(void)
285 /*FIXME(file,"(): stub\n");*/
289 /******************************************************************************
290 * AreFileApisANSI [KERNEL32.105] Determines if file functions are using ANSI
293 * TRUE: Set of file functions is using ANSI code page
294 * FALSE: Set of file functions is using OEM code page
296 BOOL32 WINAPI
AreFileApisANSI(void)
298 FIXME(file
,"(void): stub\n");