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
);
31 /***********************************************************************
32 * WriteFile (KERNEL32.578)
34 BOOL32 WINAPI
WriteFile(HFILE32 hFile
, LPVOID lpBuffer
, DWORD numberOfBytesToWrite
,
35 LPDWORD numberOfBytesWritten
, LPOVERLAPPED lpOverlapped
)
39 res
= _lwrite32(hFile
,lpBuffer
,numberOfBytesToWrite
);
41 SetLastError(ErrnoToLastError(errno
));
44 if(numberOfBytesWritten
)
45 *numberOfBytesWritten
= res
;
49 /***********************************************************************
50 * ReadFile (KERNEL32.428)
52 BOOL32 WINAPI
ReadFile(HFILE32 hFile
, LPVOID lpBuffer
, DWORD numtoread
,
53 LPDWORD numread
, LPOVERLAPPED lpOverlapped
)
57 actual_read
= _lread32(hFile
,lpBuffer
,numtoread
);
58 if(actual_read
== -1) {
59 SetLastError(ErrnoToLastError(errno
));
63 *numread
= actual_read
;
69 /***********************************************************************
70 * ReadFileEx (KERNEL32.)
72 typedef /* from winbase.h */
74 (WINAPI
*LPOVERLAPPED_COMPLETION_ROUTINE
)(
76 DWORD dwNumberOfBytesTransfered
,
77 LPOVERLAPPED lpOverlapped
80 BOOL32 WINAPI
ReadFileEx(HFILE32 hFile
, LPVOID lpBuffer
, DWORD numtoread
,
81 LPOVERLAPPED lpOverlapped
,
82 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
85 fprintf(stdnimp
,"ReadFileEx file %d to buf %p num %ld %p func %p stub\n",
86 hFile
, lpBuffer
, numtoread
, lpOverlapped
, lpCompletionRoutine
);
87 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
92 /*************************************************************************
93 * CreateFile32A (KERNEL32.45)
95 * Doesn't support character devices, pipes, template files, or a
96 * lot of the 'attributes' flags yet.
98 HFILE32 WINAPI
CreateFile32A(LPCSTR filename
, DWORD access
, DWORD sharing
,
99 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
100 DWORD attributes
, HANDLE32
template)
102 int access_flags
, create_flags
;
104 /* Translate the various flags to Unix-style.
106 access_flags
= TranslateAccessFlags(access
);
107 create_flags
= TranslateCreationFlags(creation
);
110 dprintf_file(stddeb
, "CreateFile: template handles not supported.\n");
112 /* If the name starts with '\\?' or '\\.', ignore the first 3 chars.
114 if(!strncmp(filename
, "\\\\?", 3) || !strncmp(filename
, "\\\\.", 3))
117 /* If the name still starts with '\\', it's a UNC name.
119 if(!strncmp(filename
, "\\\\", 2))
121 dprintf_file(stddeb
, "CreateFile: 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 stdin
127 * or stdout, respectively.
129 if(!strcmp(filename
, "CONIN$")) return GetStdHandle( STD_INPUT_HANDLE
);
130 if(!strcmp(filename
, "CONOUT$")) return GetStdHandle( STD_OUTPUT_HANDLE
);
132 return FILE_Open( filename
, access_flags
| create_flags
);
136 /*************************************************************************
137 * CreateFile32W (KERNEL32.48)
139 HFILE32 WINAPI
CreateFile32W(LPCWSTR filename
, DWORD access
, DWORD sharing
,
140 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
141 DWORD attributes
, HANDLE32
template)
143 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
144 HFILE32 res
= CreateFile32A( afn
, access
, sharing
, security
, creation
,
145 attributes
, template );
146 HeapFree( GetProcessHeap(), 0, afn
);
150 static int TranslateAccessFlags(DWORD access_flags
)
164 case (GENERIC_READ
| GENERIC_WRITE
):
172 static int TranslateCreationFlags(DWORD create_flags
)
179 rc
= O_CREAT
| O_EXCL
;
183 rc
= O_CREAT
| O_TRUNC
;
194 case TRUNCATE_EXISTING
:
203 /**************************************************************************
204 * SetFileAttributes16 (KERNEL.421)
206 BOOL16 WINAPI
SetFileAttributes16( LPCSTR lpFileName
, DWORD attributes
)
208 return SetFileAttributes32A( lpFileName
, attributes
);
212 /**************************************************************************
213 * SetFileAttributes32A (KERNEL32.490)
215 BOOL32 WINAPI
SetFileAttributes32A(LPCSTR lpFileName
, DWORD attributes
)
218 DOS_FULL_NAME full_name
;
220 if (!DOSFS_GetFullName( lpFileName
, TRUE
, &full_name
))
223 dprintf_file(stddeb
,"SetFileAttributes(%s,%lx)\n",lpFileName
,attributes
);
224 if (attributes
& FILE_ATTRIBUTE_NORMAL
) {
225 attributes
&= ~FILE_ATTRIBUTE_NORMAL
;
227 fprintf(stdnimp
,"SetFileAttributesA(%s):%lx illegal combination with FILE_ATTRIBUTE_NORMAL.\n",
228 lpFileName
,attributes
);
230 if(stat(full_name
.long_name
,&buf
)==-1)
232 SetLastError(ErrnoToLastError(errno
));
235 if (attributes
& FILE_ATTRIBUTE_READONLY
)
237 buf
.st_mode
&= ~0222; /* octal!, clear write permission bits */
238 attributes
&= ~FILE_ATTRIBUTE_READONLY
;
240 attributes
&= ~(FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
242 fprintf(stdnimp
,"SetFileAttributesA(%s):%lx attribute(s) not implemented.\n",lpFileName
,attributes
);
243 if (-1==chmod(full_name
.long_name
,buf
.st_mode
))
245 SetLastError(ErrnoToLastError(errno
));
252 /**************************************************************************
253 * SetFileAttributes32W (KERNEL32.491)
255 BOOL32 WINAPI
SetFileAttributes32W(LPCWSTR lpFileName
, DWORD attributes
)
257 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName
);
258 BOOL32 res
= SetFileAttributes32A( afn
, attributes
);
259 HeapFree( GetProcessHeap(), 0, afn
);
264 /**************************************************************************
265 * SetFileApisToOEM (KERNEL32.645)
267 VOID WINAPI
SetFileApisToOEM(void)
269 /*fprintf(stdnimp,"SetFileApisToOEM(),stub!\n");*/
273 /**************************************************************************
274 * SetFileApisToANSI (KERNEL32.644)
276 VOID WINAPI
SetFileApisToANSI(void)
278 /*fprintf(stdnimp,"SetFileApisToANSI(),stub!\n");*/
282 /**************************************************************************
283 * AreFileApisANSI (KERNEL32.105)
285 BOOL32 WINAPI
AreFileApisANSI(void)
287 fprintf(stdnimp
,"AreFileApisANSI(),stub!\n");