Commit | Line | Data |
---|---|---|
f6a70969 EP |
1 | /* |
2 | * File handling functions | |
3 | * | |
4 | * Copyright 1993 John Burton | |
5 | * Copyright 1996 Alexandre Julliard | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2.1 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
360a3f91 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
f6a70969 EP |
20 | * |
21 | * TODO: | |
22 | * Fix the CopyFileEx methods to implement the "extended" functionality. | |
23 | * Right now, they simply call the CopyFile method. | |
24 | */ | |
25 | ||
26 | #include "config.h" | |
27 | #include "wine/port.h" | |
28 | ||
e37c6e18 | 29 | #include <stdarg.h> |
f6a70969 EP |
30 | #include <stdio.h> |
31 | #include <assert.h> | |
32 | ||
33 | #define NONAMELESSUNION | |
34 | #define NONAMELESSSTRUCT | |
35 | #include "winerror.h" | |
36 | #include "windef.h" | |
37 | #include "winbase.h" | |
38 | #include "winternl.h" | |
39 | #include "wine/winbase16.h" | |
f6a70969 | 40 | #include "kernel_private.h" |
f6a70969 EP |
41 | #include "wine/unicode.h" |
42 | #include "wine/debug.h" | |
43 | ||
44 | WINE_DEFAULT_DEBUG_CHANNEL(file); | |
45 | ||
62b6bef3 | 46 | |
f6a70969 | 47 | /*********************************************************************** |
62b6bef3 | 48 | * GetProfileInt (KERNEL.57) |
f6a70969 | 49 | */ |
62b6bef3 | 50 | UINT16 WINAPI GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val ) |
f6a70969 | 51 | { |
62b6bef3 | 52 | return GetPrivateProfileInt16( section, entry, def_val, "win.ini" ); |
f6a70969 EP |
53 | } |
54 | ||
55 | ||
56 | /*********************************************************************** | |
62b6bef3 | 57 | * GetProfileString (KERNEL.58) |
f6a70969 | 58 | */ |
62b6bef3 AJ |
59 | INT16 WINAPI GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val, |
60 | LPSTR buffer, UINT16 len ) | |
f6a70969 | 61 | { |
62b6bef3 AJ |
62 | return GetPrivateProfileString16( section, entry, def_val, |
63 | buffer, len, "win.ini" ); | |
f6a70969 EP |
64 | } |
65 | ||
62b6bef3 AJ |
66 | |
67 | /*********************************************************************** | |
68 | * WriteProfileString (KERNEL.59) | |
69 | */ | |
70 | BOOL16 WINAPI WriteProfileString16( LPCSTR section, LPCSTR entry, | |
71 | LPCSTR string ) | |
72 | { | |
73 | return WritePrivateProfileString16( section, entry, string, "win.ini" ); | |
74 | } | |
75 | ||
76 | ||
5bfafc9d AJ |
77 | /* get the search path for the current module; helper for OpenFile16 */ |
78 | static char *get_search_path(void) | |
79 | { | |
80 | UINT len; | |
81 | char *ret, *p, module[OFS_MAXPATHNAME]; | |
82 | ||
83 | module[0] = 0; | |
84 | if (GetCurrentTask() && GetModuleFileName16( GetCurrentTask(), module, sizeof(module) )) | |
85 | { | |
86 | if (!(p = strrchr( module, '\\' ))) p = module; | |
87 | *p = 0; | |
88 | } | |
89 | ||
90 | len = (2 + /* search order: first current dir */ | |
91 | GetSystemDirectoryA( NULL, 0 ) + 1 + /* then system dir */ | |
92 | GetWindowsDirectoryA( NULL, 0 ) + 1 + /* then windows dir */ | |
93 | strlen( module ) + 1 + /* then module path */ | |
94 | GetEnvironmentVariableA( "PATH", NULL, 0 ) + 1); /* then look in PATH */ | |
95 | if (!(ret = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL; | |
96 | strcpy( ret, ".;" ); | |
97 | p = ret + 2; | |
98 | GetSystemDirectoryA( p, ret + len - p ); | |
99 | p += strlen( p ); | |
100 | *p++ = ';'; | |
101 | GetWindowsDirectoryA( p, ret + len - p ); | |
102 | p += strlen( p ); | |
103 | *p++ = ';'; | |
104 | if (module[0]) | |
105 | { | |
106 | strcpy( p, module ); | |
107 | p += strlen( p ); | |
108 | *p++ = ';'; | |
109 | } | |
110 | GetEnvironmentVariableA( "PATH", p, ret + len - p ); | |
111 | return ret; | |
112 | } | |
113 | ||
114 | /*********************************************************************** | |
115 | * OpenFile (KERNEL.74) | |
116 | * OpenFileEx (KERNEL.360) | |
117 | */ | |
118 | HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode ) | |
119 | { | |
120 | HFILE hFileRet; | |
121 | HANDLE handle; | |
122 | FILETIME filetime; | |
123 | WORD filedatetime[2]; | |
27a20044 | 124 | const char *p, *filename; |
5bfafc9d AJ |
125 | |
126 | if (!ofs) return HFILE_ERROR; | |
127 | ||
128 | TRACE("%s %s %s %s%s%s%s%s%s%s%s%s\n",debugstr_a(name), | |
129 | ((mode & 0x3 )==OF_READ)?"OF_READ": | |
130 | ((mode & 0x3 )==OF_WRITE)?"OF_WRITE": | |
131 | ((mode & 0x3 )==OF_READWRITE)?"OF_READWRITE":"unknown", | |
132 | ((mode & 0x70 )==OF_SHARE_COMPAT)?"OF_SHARE_COMPAT": | |
133 | ((mode & 0x70 )==OF_SHARE_DENY_NONE)?"OF_SHARE_DENY_NONE": | |
134 | ((mode & 0x70 )==OF_SHARE_DENY_READ)?"OF_SHARE_DENY_READ": | |
135 | ((mode & 0x70 )==OF_SHARE_DENY_WRITE)?"OF_SHARE_DENY_WRITE": | |
136 | ((mode & 0x70 )==OF_SHARE_EXCLUSIVE)?"OF_SHARE_EXCLUSIVE":"unknown", | |
137 | ((mode & OF_PARSE )==OF_PARSE)?"OF_PARSE ":"", | |
138 | ((mode & OF_DELETE )==OF_DELETE)?"OF_DELETE ":"", | |
139 | ((mode & OF_VERIFY )==OF_VERIFY)?"OF_VERIFY ":"", | |
140 | ((mode & OF_SEARCH )==OF_SEARCH)?"OF_SEARCH ":"", | |
141 | ((mode & OF_CANCEL )==OF_CANCEL)?"OF_CANCEL ":"", | |
142 | ((mode & OF_CREATE )==OF_CREATE)?"OF_CREATE ":"", | |
143 | ((mode & OF_PROMPT )==OF_PROMPT)?"OF_PROMPT ":"", | |
144 | ((mode & OF_EXIST )==OF_EXIST)?"OF_EXIST ":"", | |
145 | ((mode & OF_REOPEN )==OF_REOPEN)?"OF_REOPEN ":"" | |
146 | ); | |
147 | ||
5bfafc9d AJ |
148 | if (mode & OF_PARSE) |
149 | { | |
643617f2 | 150 | OpenFile( name, ofs, mode ); |
5bfafc9d AJ |
151 | return 0; |
152 | } | |
153 | ||
5bfafc9d AJ |
154 | if (mode & OF_CREATE) |
155 | { | |
643617f2 AJ |
156 | handle = (HANDLE)OpenFile( name, ofs, mode ); |
157 | if (handle == (HANDLE)HFILE_ERROR) goto error; | |
5bfafc9d AJ |
158 | } |
159 | else | |
160 | { | |
643617f2 AJ |
161 | ofs->cBytes = sizeof(OFSTRUCT); |
162 | ofs->nErrCode = 0; | |
163 | if (mode & OF_REOPEN) name = ofs->szPathName; | |
164 | ||
165 | if (!name) return HFILE_ERROR; | |
166 | ||
167 | /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName | |
168 | Are there any cases where getting the path here is wrong? | |
169 | Uwe Bonnes 1997 Apr 2 */ | |
170 | if (!GetFullPathNameA( name, sizeof(ofs->szPathName), ofs->szPathName, NULL )) goto error; | |
171 | ||
5bfafc9d AJ |
172 | /* If OF_SEARCH is set, ignore the given path */ |
173 | ||
27a20044 | 174 | filename = name; |
5bfafc9d AJ |
175 | if ((mode & OF_SEARCH) && !(mode & OF_REOPEN)) |
176 | { | |
177 | /* First try the file name as is */ | |
178 | if (GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES) filename = NULL; | |
179 | else | |
180 | { | |
181 | /* Now remove the path */ | |
182 | if (filename[0] && (filename[1] == ':')) filename += 2; | |
183 | if ((p = strrchr( filename, '\\' ))) filename = p + 1; | |
184 | if ((p = strrchr( filename, '/' ))) filename = p + 1; | |
185 | if (!filename[0]) | |
186 | { | |
187 | SetLastError( ERROR_FILE_NOT_FOUND ); | |
188 | goto error; | |
189 | } | |
190 | } | |
191 | } | |
192 | ||
193 | /* Now look for the file */ | |
194 | ||
195 | if (filename) | |
196 | { | |
197 | BOOL found; | |
198 | char *path = get_search_path(); | |
199 | ||
200 | if (!path) goto error; | |
201 | found = SearchPathA( path, filename, NULL, sizeof(ofs->szPathName), | |
202 | ofs->szPathName, NULL ); | |
203 | HeapFree( GetProcessHeap(), 0, path ); | |
204 | if (!found) goto error; | |
205 | } | |
206 | ||
207 | TRACE("found %s\n", debugstr_a(ofs->szPathName) ); | |
208 | ||
209 | if (mode & OF_DELETE) | |
210 | { | |
211 | if (!DeleteFileA( ofs->szPathName )) goto error; | |
212 | TRACE("(%s): OF_DELETE return = OK\n", name); | |
213 | return 1; | |
214 | } | |
215 | ||
216 | handle = (HANDLE)_lopen( ofs->szPathName, mode ); | |
217 | if (handle == INVALID_HANDLE_VALUE) goto error; | |
218 | ||
219 | GetFileTime( handle, NULL, NULL, &filetime ); | |
220 | FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] ); | |
221 | if ((mode & OF_VERIFY) && (mode & OF_REOPEN)) | |
222 | { | |
223 | if (ofs->Reserved1 != filedatetime[0] || ofs->Reserved2 != filedatetime[1] ) | |
224 | { | |
225 | CloseHandle( handle ); | |
226 | WARN("(%s): OF_VERIFY failed\n", name ); | |
227 | /* FIXME: what error here? */ | |
228 | SetLastError( ERROR_FILE_NOT_FOUND ); | |
229 | goto error; | |
230 | } | |
231 | } | |
232 | ofs->Reserved1 = filedatetime[0]; | |
233 | ofs->Reserved2 = filedatetime[1]; | |
234 | } | |
235 | ||
236 | TRACE("(%s): OK, return = %p\n", name, handle ); | |
237 | hFileRet = Win32HandleToDosFileHandle( handle ); | |
238 | if (hFileRet == HFILE_ERROR16) goto error; | |
239 | if (mode & OF_EXIST) _lclose16( hFileRet ); /* Return the handle, but close it first */ | |
240 | return hFileRet; | |
241 | ||
242 | error: /* We get here if there was an error opening the file */ | |
243 | ofs->nErrCode = GetLastError(); | |
244 | WARN("(%s): return = HFILE_ERROR error= %d\n", name,ofs->nErrCode ); | |
245 | return HFILE_ERROR16; | |
246 | } | |
247 | ||
248 | ||
768008fa EP |
249 | /*********************************************************************** |
250 | * _lclose (KERNEL.81) | |
251 | */ | |
252 | HFILE16 WINAPI _lclose16( HFILE16 hFile ) | |
253 | { | |
254 | if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile]) | |
255 | { | |
256 | SetLastError( ERROR_INVALID_HANDLE ); | |
257 | return HFILE_ERROR16; | |
258 | } | |
259 | TRACE("%d (handle32=%p)\n", hFile, dos_handles[hFile] ); | |
260 | CloseHandle( dos_handles[hFile] ); | |
261 | dos_handles[hFile] = 0; | |
262 | return 0; | |
263 | } | |
f6a70969 EP |
264 | |
265 | /*********************************************************************** | |
266 | * _lcreat (KERNEL.83) | |
267 | */ | |
268 | HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr ) | |
269 | { | |
270 | return Win32HandleToDosFileHandle( (HANDLE)_lcreat( path, attr ) ); | |
271 | } | |
272 | ||
273 | /*********************************************************************** | |
274 | * _llseek (KERNEL.84) | |
275 | * | |
276 | * FIXME: | |
277 | * Seeking before the start of the file should be allowed for _llseek16, | |
278 | * but cause subsequent I/O operations to fail (cf. interrupt list) | |
279 | * | |
280 | */ | |
281 | LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin ) | |
282 | { | |
283 | return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin ); | |
284 | } | |
285 | ||
286 | ||
287 | /*********************************************************************** | |
288 | * _lopen (KERNEL.85) | |
289 | */ | |
290 | HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode ) | |
291 | { | |
292 | return Win32HandleToDosFileHandle( (HANDLE)_lopen( path, mode ) ); | |
293 | } | |
294 | ||
295 | ||
296 | /*********************************************************************** | |
297 | * _lread16 (KERNEL.82) | |
298 | */ | |
299 | UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count ) | |
300 | { | |
301 | return (UINT16)_lread((HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count ); | |
302 | } | |
303 | ||
304 | ||
305 | /*********************************************************************** | |
306 | * _lwrite (KERNEL.86) | |
307 | */ | |
308 | UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count ) | |
309 | { | |
310 | return (UINT16)_hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count ); | |
311 | } | |
312 | ||
313 | /*********************************************************************** | |
314 | * _hread (KERNEL.349) | |
315 | */ | |
316 | LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count ) | |
317 | { | |
318 | LONG maxlen; | |
319 | ||
8c38b880 | 320 | TRACE("%d %08x %d\n", hFile, (DWORD)buffer, count ); |
f6a70969 EP |
321 | |
322 | /* Some programs pass a count larger than the allocated buffer */ | |
323 | maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1; | |
324 | if (count > maxlen) count = maxlen; | |
325 | return _lread((HFILE)DosFileHandleToWin32Handle(hFile), MapSL(buffer), count ); | |
326 | } | |
327 | ||
328 | ||
329 | /*********************************************************************** | |
330 | * _lread (KERNEL.82) | |
331 | */ | |
332 | UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count ) | |
333 | { | |
334 | return (UINT16)WIN16_hread( hFile, buffer, (LONG)count ); | |
335 | } | |
336 | ||
337 | ||
dbecf5c9 AJ |
338 | /*********************************************************************** |
339 | * GetTempDrive (KERNEL.92) | |
340 | * A closer look at krnl386.exe shows what the SDK doesn't mention: | |
341 | * | |
342 | * returns: | |
343 | * AL: driveletter | |
344 | * AH: ':' - yes, some kernel code even does stosw with | |
345 | * the returned AX. | |
346 | * DX: 1 for success | |
347 | */ | |
348 | UINT WINAPI GetTempDrive( BYTE ignored ) | |
349 | { | |
350 | WCHAR buffer[8]; | |
351 | BYTE ret; | |
352 | ||
353 | if (GetTempPathW( 8, buffer )) ret = (BYTE)toupperW(buffer[0]); | |
354 | else ret = 'C'; | |
355 | return MAKELONG( ret | (':' << 8), 1 ); | |
356 | } | |
357 | ||
358 | ||
f6a70969 EP |
359 | /*********************************************************************** |
360 | * GetTempFileName (KERNEL.97) | |
361 | */ | |
362 | UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique, | |
363 | LPSTR buffer ) | |
364 | { | |
365 | char temppath[MAX_PATH]; | |
366 | char *prefix16 = NULL; | |
367 | UINT16 ret; | |
368 | ||
369 | if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */ | |
370 | { | |
371 | GetCurrentDirectoryA(sizeof(temppath), temppath); | |
372 | drive |= temppath[0]; | |
373 | } | |
374 | ||
375 | if (drive & TF_FORCEDRIVE) | |
376 | { | |
377 | char d[3]; | |
378 | ||
379 | d[0] = drive & ~TF_FORCEDRIVE; | |
380 | d[1] = ':'; | |
381 | d[2] = '\0'; | |
382 | if (GetDriveTypeA(d) == DRIVE_NO_ROOT_DIR) | |
383 | { | |
384 | drive &= ~TF_FORCEDRIVE; | |
385 | WARN("invalid drive %d specified\n", drive ); | |
386 | } | |
387 | } | |
388 | ||
389 | if (drive & TF_FORCEDRIVE) | |
390 | sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE ); | |
391 | else | |
392 | GetTempPathA( MAX_PATH, temppath ); | |
393 | ||
394 | if (prefix) | |
395 | { | |
396 | prefix16 = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + 2); | |
397 | *prefix16 = '~'; | |
398 | strcpy(prefix16 + 1, prefix); | |
399 | } | |
400 | ||
401 | ret = GetTempFileNameA( temppath, prefix16, unique, buffer ); | |
402 | ||
5ad7d858 | 403 | HeapFree(GetProcessHeap(), 0, prefix16); |
f6a70969 EP |
404 | return ret; |
405 | } | |
406 | ||
62b6bef3 AJ |
407 | |
408 | /*********************************************************************** | |
409 | * GetPrivateProfileInt (KERNEL.127) | |
f6a70969 | 410 | */ |
62b6bef3 AJ |
411 | UINT16 WINAPI GetPrivateProfileInt16( LPCSTR section, LPCSTR entry, |
412 | INT16 def_val, LPCSTR filename ) | |
f6a70969 | 413 | { |
62b6bef3 AJ |
414 | /* we used to have some elaborate return value limitation (<= -32768 etc.) |
415 | * here, but Win98SE doesn't care about this at all, so I deleted it. | |
416 | * AFAIR versions prior to Win9x had these limits, though. */ | |
417 | return (INT16)GetPrivateProfileIntA(section,entry,def_val,filename); | |
418 | } | |
419 | ||
420 | ||
421 | /*********************************************************************** | |
422 | * WritePrivateProfileString (KERNEL.129) | |
423 | */ | |
424 | BOOL16 WINAPI WritePrivateProfileString16( LPCSTR section, LPCSTR entry, | |
425 | LPCSTR string, LPCSTR filename ) | |
426 | { | |
427 | return WritePrivateProfileStringA(section,entry,string,filename); | |
428 | } | |
429 | ||
430 | ||
431 | /*********************************************************************** | |
432 | * GetWindowsDirectory (KERNEL.134) | |
433 | */ | |
434 | UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count ) | |
435 | { | |
436 | return GetWindowsDirectoryA( path, count ); | |
437 | } | |
438 | ||
439 | ||
440 | /*********************************************************************** | |
441 | * GetSystemDirectory (KERNEL.135) | |
442 | */ | |
443 | UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count ) | |
444 | { | |
445 | return GetSystemDirectoryA( path, count ); | |
446 | } | |
447 | ||
448 | ||
449 | /*********************************************************************** | |
450 | * GetDriveType (KERNEL.136) | |
b8d9b619 MA |
451 | * Get the type of a drive in Win16. |
452 | * | |
453 | * RETURNS | |
454 | * The type of the Drive. For a list see GetDriveTypeW from kernel32. | |
455 | * | |
456 | * NOTES | |
457 | * Note that it returns DRIVE_REMOTE for CD-ROMs, since MSCDEX uses the | |
458 | * remote drive API. The return value DRIVE_REMOTE for CD-ROMs has been | |
459 | * verified on Win 3.11 and Windows 95. Some programs rely on it, so don't | |
460 | * do any pseudo-clever changes. | |
62b6bef3 AJ |
461 | */ |
462 | UINT16 WINAPI GetDriveType16( UINT16 drive ) /* [in] number (NOT letter) of drive */ | |
463 | { | |
464 | UINT type; | |
465 | WCHAR root[3]; | |
466 | ||
467 | root[0] = 'A' + drive; | |
468 | root[1] = ':'; | |
469 | root[2] = 0; | |
470 | type = GetDriveTypeW( root ); | |
471 | if (type == DRIVE_CDROM) type = DRIVE_REMOTE; | |
27a20044 | 472 | else if (type == DRIVE_NO_ROOT_DIR) type = DRIVE_UNKNOWN; |
62b6bef3 AJ |
473 | return type; |
474 | } | |
475 | ||
476 | ||
477 | /*********************************************************************** | |
478 | * GetProfileSectionNames (KERNEL.142) | |
479 | */ | |
480 | WORD WINAPI GetProfileSectionNames16(LPSTR buffer, WORD size) | |
481 | ||
482 | { | |
483 | return GetPrivateProfileSectionNamesA(buffer,size,"win.ini"); | |
484 | } | |
485 | ||
486 | ||
487 | /*********************************************************************** | |
488 | * GetPrivateProfileSectionNames (KERNEL.143) | |
489 | */ | |
490 | WORD WINAPI GetPrivateProfileSectionNames16( LPSTR buffer, WORD size, | |
491 | LPCSTR filename ) | |
492 | { | |
493 | return GetPrivateProfileSectionNamesA(buffer,size,filename); | |
494 | } | |
495 | ||
496 | ||
497 | /*********************************************************************** | |
498 | * CreateDirectory (KERNEL.144) | |
499 | */ | |
500 | BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy ) | |
501 | { | |
502 | return CreateDirectoryA( path, NULL ); | |
503 | } | |
504 | ||
505 | ||
506 | /*********************************************************************** | |
507 | * RemoveDirectory (KERNEL.145) | |
508 | */ | |
509 | BOOL16 WINAPI RemoveDirectory16( LPCSTR path ) | |
510 | { | |
511 | return RemoveDirectoryA( path ); | |
512 | } | |
513 | ||
514 | ||
515 | /*********************************************************************** | |
516 | * DeleteFile (KERNEL.146) | |
517 | */ | |
518 | BOOL16 WINAPI DeleteFile16( LPCSTR path ) | |
519 | { | |
520 | return DeleteFileA( path ); | |
f6a70969 EP |
521 | } |
522 | ||
523 | ||
524 | /*********************************************************************** | |
525 | * SetHandleCount (KERNEL.199) | |
526 | */ | |
527 | UINT16 WINAPI SetHandleCount16( UINT16 count ) | |
528 | { | |
529 | return SetHandleCount( count ); | |
530 | } | |
2ac34461 AJ |
531 | |
532 | ||
62b6bef3 AJ |
533 | /*********************************************************************** |
534 | * _hread16 (KERNEL.349) | |
535 | */ | |
536 | LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count) | |
537 | { | |
538 | return _lread( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count ); | |
539 | } | |
540 | ||
541 | ||
542 | /*********************************************************************** | |
543 | * _hwrite (KERNEL.350) | |
544 | */ | |
545 | LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count ) | |
546 | { | |
547 | return _hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count ); | |
548 | } | |
549 | ||
550 | ||
551 | /*********************************************************************** | |
552 | * WritePrivateProfileStruct (KERNEL.406) | |
553 | */ | |
554 | BOOL16 WINAPI WritePrivateProfileStruct16 (LPCSTR section, LPCSTR key, | |
555 | LPVOID buf, UINT16 bufsize, LPCSTR filename) | |
556 | { | |
557 | return WritePrivateProfileStructA( section, key, buf, bufsize, filename ); | |
558 | } | |
559 | ||
560 | ||
561 | /*********************************************************************** | |
562 | * GetPrivateProfileStruct (KERNEL.407) | |
563 | */ | |
564 | BOOL16 WINAPI GetPrivateProfileStruct16(LPCSTR section, LPCSTR key, | |
565 | LPVOID buf, UINT16 len, LPCSTR filename) | |
566 | { | |
567 | return GetPrivateProfileStructA( section, key, buf, len, filename ); | |
568 | } | |
569 | ||
570 | ||
06c46d9a AJ |
571 | /*********************************************************************** |
572 | * GetCurrentDirectory (KERNEL.411) | |
573 | */ | |
574 | UINT16 WINAPI GetCurrentDirectory16( UINT16 buflen, LPSTR buf ) | |
575 | { | |
576 | return GetCurrentDirectoryA( buflen, buf ); | |
577 | } | |
578 | ||
579 | ||
62b6bef3 AJ |
580 | /*********************************************************************** |
581 | * SetCurrentDirectory (KERNEL.412) | |
582 | */ | |
583 | BOOL16 WINAPI SetCurrentDirectory16( LPCSTR dir ) | |
584 | { | |
bd1fdedd AJ |
585 | char fulldir[MAX_PATH]; |
586 | ||
587 | if (!GetFullPathNameA( dir, MAX_PATH, fulldir, NULL )) return FALSE; | |
588 | ||
06c46d9a AJ |
589 | if (!SetCurrentDirectoryA( dir )) return FALSE; |
590 | ||
bd1fdedd AJ |
591 | if (fulldir[0] && fulldir[1] == ':') |
592 | { | |
06c46d9a | 593 | TDB *pTask = GlobalLock16( GetCurrentTask() ); |
bd1fdedd | 594 | char env_var[4] = "=A:"; |
06c46d9a | 595 | |
bd1fdedd AJ |
596 | env_var[1] = fulldir[0]; |
597 | SetEnvironmentVariableA( env_var, fulldir ); | |
06c46d9a AJ |
598 | |
599 | /* update the directory in the TDB */ | |
600 | if (pTask) | |
601 | { | |
602 | pTask->curdrive = 0x80 | (fulldir[0] - 'A'); | |
603 | GetShortPathNameA( fulldir + 2, pTask->curdir, sizeof(pTask->curdir) ); | |
604 | } | |
bd1fdedd | 605 | } |
06c46d9a | 606 | return TRUE; |
62b6bef3 AJ |
607 | } |
608 | ||
609 | ||
2ac34461 AJ |
610 | /************************************************************************* |
611 | * FindFirstFile (KERNEL.413) | |
612 | */ | |
613 | HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATAA *data ) | |
614 | { | |
615 | HGLOBAL16 h16; | |
616 | HANDLE handle, *ptr; | |
617 | ||
618 | if (!(h16 = GlobalAlloc16( GMEM_MOVEABLE, sizeof(handle) ))) return INVALID_HANDLE_VALUE16; | |
619 | ptr = GlobalLock16( h16 ); | |
620 | *ptr = handle = FindFirstFileA( path, data ); | |
621 | GlobalUnlock16( h16 ); | |
622 | ||
623 | if (handle == INVALID_HANDLE_VALUE) | |
624 | { | |
625 | GlobalFree16( h16 ); | |
626 | h16 = INVALID_HANDLE_VALUE16; | |
627 | } | |
628 | return h16; | |
629 | } | |
630 | ||
631 | ||
632 | /************************************************************************* | |
633 | * FindNextFile (KERNEL.414) | |
634 | */ | |
635 | BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATAA *data ) | |
636 | { | |
637 | HANDLE *ptr; | |
638 | BOOL ret = FALSE; | |
639 | ||
640 | if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle ))) | |
641 | { | |
642 | SetLastError( ERROR_INVALID_HANDLE ); | |
643 | return ret; | |
644 | } | |
645 | ret = FindNextFileA( *ptr, data ); | |
646 | GlobalUnlock16( handle ); | |
647 | return ret; | |
648 | } | |
649 | ||
650 | ||
651 | /************************************************************************* | |
652 | * FindClose (KERNEL.415) | |
653 | */ | |
654 | BOOL16 WINAPI FindClose16( HANDLE16 handle ) | |
655 | { | |
656 | HANDLE *ptr; | |
657 | ||
658 | if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle ))) | |
659 | { | |
660 | SetLastError( ERROR_INVALID_HANDLE ); | |
661 | return FALSE; | |
662 | } | |
663 | FindClose( *ptr ); | |
664 | GlobalUnlock16( handle ); | |
665 | GlobalFree16( handle ); | |
666 | return TRUE; | |
667 | } | |
62b6bef3 AJ |
668 | |
669 | ||
670 | /*********************************************************************** | |
671 | * WritePrivateProfileSection (KERNEL.416) | |
672 | */ | |
673 | BOOL16 WINAPI WritePrivateProfileSection16( LPCSTR section, | |
674 | LPCSTR string, LPCSTR filename ) | |
675 | { | |
676 | return WritePrivateProfileSectionA( section, string, filename ); | |
677 | } | |
678 | ||
679 | ||
680 | /*********************************************************************** | |
681 | * WriteProfileSection (KERNEL.417) | |
682 | */ | |
683 | BOOL16 WINAPI WriteProfileSection16( LPCSTR section, LPCSTR keys_n_values) | |
684 | { | |
685 | return WritePrivateProfileSection16( section, keys_n_values, "win.ini"); | |
686 | } | |
687 | ||
688 | ||
689 | /*********************************************************************** | |
690 | * GetPrivateProfileSection (KERNEL.418) | |
691 | */ | |
692 | INT16 WINAPI GetPrivateProfileSection16( LPCSTR section, LPSTR buffer, | |
693 | UINT16 len, LPCSTR filename ) | |
694 | { | |
695 | return GetPrivateProfileSectionA( section, buffer, len, filename ); | |
696 | } | |
697 | ||
698 | ||
699 | /*********************************************************************** | |
700 | * GetProfileSection (KERNEL.419) | |
701 | */ | |
702 | INT16 WINAPI GetProfileSection16( LPCSTR section, LPSTR buffer, UINT16 len ) | |
703 | { | |
704 | return GetPrivateProfileSection16( section, buffer, len, "win.ini" ); | |
705 | } | |
706 | ||
707 | ||
708 | /************************************************************************** | |
709 | * GetFileAttributes (KERNEL.420) | |
710 | */ | |
711 | DWORD WINAPI GetFileAttributes16( LPCSTR name ) | |
712 | { | |
713 | return GetFileAttributesA( name ); | |
714 | } | |
715 | ||
716 | ||
717 | /************************************************************************** | |
718 | * SetFileAttributes (KERNEL.421) | |
719 | */ | |
720 | BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes ) | |
721 | { | |
722 | return SetFileAttributesA( lpFileName, attributes ); | |
723 | } | |
724 | ||
725 | ||
726 | /*********************************************************************** | |
727 | * GetDiskFreeSpace (KERNEL.422) | |
728 | */ | |
729 | BOOL16 WINAPI GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors, | |
730 | LPDWORD sector_bytes, LPDWORD free_clusters, | |
731 | LPDWORD total_clusters ) | |
732 | { | |
733 | return GetDiskFreeSpaceA( root, cluster_sectors, sector_bytes, | |
734 | free_clusters, total_clusters ); | |
735 | } | |
13ea5155 MM |
736 | |
737 | /*********************************************************************** | |
738 | * FileCDR (KERNEL.130) | |
739 | */ | |
740 | FARPROC16 WINAPI FileCDR16(FARPROC16 x) | |
741 | { | |
742 | FIXME("(%p): stub\n", x); | |
743 | return (FARPROC16)TRUE; | |
744 | } |