2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
11 #include <sys/types.h>
29 static int TranslateCreationFlags(DWORD create_flags);
30 static int TranslateAccessFlags(DWORD access_flags);
32 /***********************************************************************
33 * WriteFile (KERNEL32.578)
35 BOOL32 WriteFile(HFILE32 hFile, LPVOID lpBuffer, DWORD numberOfBytesToWrite,
36 LPDWORD numberOfBytesWritten, LPOVERLAPPED lpOverlapped)
40 res = _lwrite32(hFile,lpBuffer,numberOfBytesToWrite);
42 SetLastError(ErrnoToLastError(errno));
45 if(numberOfBytesWritten)
46 *numberOfBytesWritten = res;
50 /***********************************************************************
51 * ReadFile (KERNEL32.428)
53 BOOL32 ReadFile(HFILE32 hFile, LPVOID lpBuffer, DWORD numtoread,
54 LPDWORD numread, LPOVERLAPPED lpOverlapped)
58 actual_read = _lread32(hFile,lpBuffer,numtoread);
59 if(actual_read == -1) {
60 SetLastError(ErrnoToLastError(errno));
64 *numread = actual_read;
70 /*************************************************************************
71 * CreateFile32A (KERNEL32.45)
73 * Doesn't support character devices, pipes, template files, or a
74 * lot of the 'attributes' flags yet.
76 HFILE32 CreateFile32A(LPCSTR filename, DWORD access, DWORD sharing,
77 LPSECURITY_ATTRIBUTES security, DWORD creation,
78 DWORD attributes, HANDLE32 template)
80 int access_flags, create_flags;
82 /* Translate the various flags to Unix-style.
84 access_flags = TranslateAccessFlags(access);
85 create_flags = TranslateCreationFlags(creation);
88 dprintf_file(stddeb, "CreateFile: template handles not supported.\n");
90 /* If the name starts with '\\?' or '\\.', ignore the first 3 chars.
92 if(!strncmp(filename, "\\\\?", 3) || !strncmp(filename, "\\\\.", 3))
95 /* If the name still starts with '\\', it's a UNC name.
97 if(!strncmp(filename, "\\\\", 2))
99 dprintf_file(stddeb, "CreateFile: UNC names not supported.\n");
100 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
101 return HFILE_ERROR32;
104 /* If the name is either CONIN$ or CONOUT$, give them stdin
105 * or stdout, respectively.
107 if(!strcmp(filename, "CONIN$")) return GetStdHandle( STD_INPUT_HANDLE );
108 if(!strcmp(filename, "CONOUT$")) return GetStdHandle( STD_OUTPUT_HANDLE );
110 return FILE_Open( filename, access_flags | create_flags );
114 /*************************************************************************
115 * CreateFile32W (KERNEL32.48)
117 HFILE32 CreateFile32W(LPCWSTR filename, DWORD access, DWORD sharing,
118 LPSECURITY_ATTRIBUTES security, DWORD creation,
119 DWORD attributes, HANDLE32 template)
121 LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
122 HFILE32 res = CreateFile32A( afn, access, sharing, security, creation,
123 attributes, template );
124 HeapFree( GetProcessHeap(), 0, afn );
128 static int TranslateAccessFlags(DWORD access_flags)
142 case (GENERIC_READ | GENERIC_WRITE):
150 static int TranslateCreationFlags(DWORD create_flags)
157 rc = O_CREAT | O_EXCL;
161 rc = O_CREAT | O_TRUNC;
172 case TRUNCATE_EXISTING:
181 /**************************************************************************
182 * SetFileAttributes16 (KERNEL.421)
184 BOOL16 SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
186 return SetFileAttributes32A( lpFileName, attributes );
190 /**************************************************************************
191 * SetFileAttributes32A (KERNEL32.490)
193 BOOL32 SetFileAttributes32A(LPCSTR lpFileName, DWORD attributes)
196 DOS_FULL_NAME full_name;
198 if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name ))
201 dprintf_file(stddeb,"SetFileAttributes(%s,%lx)\n",lpFileName,attributes);
202 if(stat(full_name.long_name,&buf)==-1)
204 SetLastError(ErrnoToLastError(errno));
207 if (attributes & FILE_ATTRIBUTE_READONLY)
209 buf.st_mode &= ~0222; /* octal!, clear write permission bits */
210 attributes &= ~FILE_ATTRIBUTE_READONLY;
212 attributes &= ~(FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
214 fprintf(stdnimp,"SetFileAttributesA(%s):%lx attribute(s) not implemented.\n",lpFileName,attributes);
215 if (-1==chmod(full_name.long_name,buf.st_mode))
217 SetLastError(ErrnoToLastError(errno));
223 /**************************************************************************
224 * SetFileAttributes32W (KERNEL32.491)
226 BOOL32 SetFileAttributes32W(LPCWSTR lpFileName, DWORD attributes)
228 LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
229 BOOL32 res = SetFileAttributes32A( afn, attributes );
230 HeapFree( GetProcessHeap(), 0, afn );
234 VOID SetFileApisToOEM()
236 fprintf(stdnimp,"SetFileApisToOEM(),stub!\n");
239 VOID SetFileApisToANSI()
241 fprintf(stdnimp,"SetFileApisToANSI(),stub!\n");
244 BOOL32 AreFileApisANSI()
246 fprintf(stdnimp,"AreFileApisANSI(),stub!\n");
253 HFILE32 hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,
254 DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh )
256 fprintf(stdnimp,"LockFile(%d,0x%08lx%08lx,0x%08lx%08lx),stub!\n",
257 hFile,dwFileOffsetHigh,dwFileOffsetLow,
258 nNumberOfBytesToLockHigh,nNumberOfBytesToLockLow
265 HFILE32 hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,
266 DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh )
268 fprintf(stdnimp,"UnlockFile(%d,0x%08lx%08lx,0x%08lx%08lx),stub!\n",
269 hFile,dwFileOffsetHigh,dwFileOffsetLow,
270 nNumberOfBytesToUnlockHigh,nNumberOfBytesToUnlockLow