2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
11 #include <sys/types.h>
28 DWORD
ErrnoToLastError(int errno_num
);
30 static int TranslateCreationFlags(DWORD create_flags
);
31 static int TranslateAccessFlags(DWORD access_flags
);
33 /***********************************************************************
34 * WriteFile (KERNEL32.578)
36 BOOL32
WriteFile(HFILE32 hFile
, LPVOID lpBuffer
, DWORD numberOfBytesToWrite
,
37 LPDWORD numberOfBytesWritten
, LPOVERLAPPED lpOverlapped
)
41 res
= _lwrite32(hFile
,lpBuffer
,numberOfBytesToWrite
);
43 SetLastError(ErrnoToLastError(errno
));
46 if(numberOfBytesWritten
)
47 *numberOfBytesWritten
= res
;
51 /***********************************************************************
52 * ReadFile (KERNEL32.428)
54 BOOL32
ReadFile(HFILE32 hFile
, LPVOID lpBuffer
, DWORD numtoread
,
55 LPDWORD numread
, LPOVERLAPPED lpOverlapped
)
59 actual_read
= _lread32(hFile
,lpBuffer
,numtoread
);
60 if(actual_read
== -1) {
61 SetLastError(ErrnoToLastError(errno
));
65 *numread
= actual_read
;
71 /*************************************************************************
72 * CreateFile32A (KERNEL32.45)
74 * Doesn't support character devices, pipes, template files, or a
75 * lot of the 'attributes' flags yet.
77 HFILE32
CreateFile32A(LPCSTR filename
, DWORD access
, DWORD sharing
,
78 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
79 DWORD attributes
, HANDLE32
template)
81 int access_flags
, create_flags
;
83 /* Translate the various flags to Unix-style.
85 access_flags
= TranslateAccessFlags(access
);
86 create_flags
= TranslateCreationFlags(creation
);
89 dprintf_file(stddeb
, "CreateFile: template handles not supported.\n");
91 /* If the name starts with '\\?' or '\\.', ignore the first 3 chars.
93 if(!strncmp(filename
, "\\\\?", 3) || !strncmp(filename
, "\\\\.", 3))
96 /* If the name still starts with '\\', it's a UNC name.
98 if(!strncmp(filename
, "\\\\", 2))
100 dprintf_file(stddeb
, "CreateFile: UNC names not supported.\n");
101 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
102 return HFILE_ERROR32
;
105 /* If the name is either CONIN$ or CONOUT$, give them stdin
106 * or stdout, respectively.
108 if(!strcmp(filename
, "CONIN$")) return GetStdHandle( STD_INPUT_HANDLE
);
109 if(!strcmp(filename
, "CONOUT$")) return GetStdHandle( STD_OUTPUT_HANDLE
);
111 return FILE_Open( filename
, access_flags
| create_flags
);
115 /*************************************************************************
116 * CreateFile32W (KERNEL32.48)
118 HFILE32
CreateFile32W(LPCWSTR filename
, DWORD access
, DWORD sharing
,
119 LPSECURITY_ATTRIBUTES security
, DWORD creation
,
120 DWORD attributes
, HANDLE32
template)
122 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
123 HFILE32 res
= CreateFile32A( afn
, access
, sharing
, security
, creation
,
124 attributes
, template );
125 HeapFree( GetProcessHeap(), 0, afn
);
129 static int TranslateAccessFlags(DWORD access_flags
)
143 case (GENERIC_READ
| GENERIC_WRITE
):
151 static int TranslateCreationFlags(DWORD create_flags
)
158 rc
= O_CREAT
| O_EXCL
;
162 rc
= O_CREAT
| O_TRUNC
;
173 case TRUNCATE_EXISTING
:
182 /**************************************************************************
183 * SetFileAttributes16 (KERNEL.421)
185 BOOL16
SetFileAttributes16( LPCSTR lpFileName
, DWORD attributes
)
187 return SetFileAttributes32A( lpFileName
, attributes
);
191 /**************************************************************************
192 * SetFileAttributes32A (KERNEL32.490)
194 BOOL32
SetFileAttributes32A(LPCSTR lpFileName
, DWORD attributes
)
197 DOS_FULL_NAME full_name
;
199 if (!DOSFS_GetFullName( lpFileName
, TRUE
, &full_name
))
202 dprintf_file(stddeb
,"SetFileAttributes(%s,%lx)\n",lpFileName
,attributes
);
203 if(stat(full_name
.long_name
,&buf
)==-1)
205 SetLastError(ErrnoToLastError(errno
));
208 if (attributes
& FILE_ATTRIBUTE_READONLY
)
210 buf
.st_mode
&= ~0222; /* octal!, clear write permission bits */
211 attributes
&= ~FILE_ATTRIBUTE_READONLY
;
213 attributes
&= ~(FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
215 fprintf(stdnimp
,"SetFileAttributesA(%s):%lx attribute(s) not implemented.\n",lpFileName
,attributes
);
216 if (-1==chmod(full_name
.long_name
,buf
.st_mode
))
218 SetLastError(ErrnoToLastError(errno
));
224 /**************************************************************************
225 * SetFileAttributes32W (KERNEL32.491)
227 BOOL32
SetFileAttributes32W(LPCWSTR lpFileName
, DWORD attributes
)
229 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName
);
230 BOOL32 res
= SetFileAttributes32A( afn
, attributes
);
231 HeapFree( GetProcessHeap(), 0, afn
);
235 VOID
SetFileApisToOEM()
237 fprintf(stdnimp
,"SetFileApisToOEM(),stub!\n");
240 VOID
SetFileApisToANSI()
242 fprintf(stdnimp
,"SetFileApisToANSI(),stub!\n");
245 BOOL32
AreFileApisANSI()
247 fprintf(stdnimp
,"AreFileApisANSI(),stub!\n");