msvcrt: Simplify platform checks for exception handling functions.
[wine.git] / dlls / krnl386.exe16 / file.c
blob5eab055988357fe0cdfb4f37be3538acbfbd5f6e
1 /*
2 * File handling functions
4 * Copyright 1993 John Burton
5 * Copyright 1996 Alexandre Julliard
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.
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.
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
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * TODO:
22 * Fix the CopyFileEx methods to implement the "extended" functionality.
23 * Right now, they simply call the CopyFile method.
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <assert.h>
31 #include "winerror.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winternl.h"
35 #include "wine/winbase16.h"
36 #include "kernel16_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(file);
41 #define DOS_TABLE_SIZE 256
43 static HANDLE dos_handles[DOS_TABLE_SIZE];
45 /***********************************************************************
46 * FILE_InitProcessDosHandles
48 * Allocates the default DOS handles for a process. Called either by
49 * Win32HandleToDosFileHandle below or by the DOSVM stuff.
51 static void FILE_InitProcessDosHandles( void )
53 HANDLE hStdInput, hStdOutput, hStdError, hNull;
54 static BOOL init_done /* = FALSE */;
55 HANDLE cp = GetCurrentProcess();
57 if (init_done) return;
58 init_done = TRUE;
59 hStdInput = GetStdHandle(STD_INPUT_HANDLE);
60 hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
61 hStdError = GetStdHandle(STD_ERROR_HANDLE);
62 hNull = CreateFileA("NUL", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
63 /* Invalid console handles need to translate to real DOS handles in a new process */
64 if (!hStdInput) hStdInput = hNull;
65 if (!hStdOutput) hStdOutput = hNull;
66 if (!hStdError) hStdError = hNull;
67 DuplicateHandle(cp, hStdInput, cp, &dos_handles[0], 0, TRUE, DUPLICATE_SAME_ACCESS);
68 DuplicateHandle(cp, hStdOutput, cp, &dos_handles[1], 0, TRUE, DUPLICATE_SAME_ACCESS);
69 DuplicateHandle(cp, hStdError, cp, &dos_handles[2], 0, TRUE, DUPLICATE_SAME_ACCESS);
70 DuplicateHandle(cp, hStdError, cp, &dos_handles[3], 0, TRUE, DUPLICATE_SAME_ACCESS);
71 DuplicateHandle(cp, hStdError, cp, &dos_handles[4], 0, TRUE, DUPLICATE_SAME_ACCESS);
72 CloseHandle(hNull);
75 /***********************************************************************
76 * DosFileHandleToWin32Handle (KERNEL32.20)
78 * Return the Win32 handle for a DOS handle.
80 * Note: this is not exactly right, since on Win95 the Win32 handles
81 * are on top of DOS handles and we do it the other way
82 * around. Should be good enough though.
84 HANDLE WINAPI DosFileHandleToWin32Handle( HFILE handle )
86 HFILE16 hfile = (HFILE16)handle;
87 if (hfile < 5) FILE_InitProcessDosHandles();
88 if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile])
90 SetLastError( ERROR_INVALID_HANDLE );
91 return INVALID_HANDLE_VALUE;
93 return dos_handles[hfile];
96 /***********************************************************************
97 * Win32HandleToDosFileHandle (KERNEL32.21)
99 * Allocate a DOS handle for a Win32 handle. The Win32 handle is no
100 * longer valid after this function (even on failure).
102 * Note: this is not exactly right, since on Win95 the Win32 handles
103 * are on top of DOS handles and we do it the other way
104 * around. Should be good enough though.
106 HFILE WINAPI Win32HandleToDosFileHandle( HANDLE handle )
108 int i;
110 if (!handle || (handle == INVALID_HANDLE_VALUE))
111 return HFILE_ERROR;
113 for (i = 5; i < DOS_TABLE_SIZE; i++)
114 if (!dos_handles[i])
116 dos_handles[i] = handle;
117 TRACE("Got %d for h32 %p\n", i, handle );
118 return (HFILE)i;
120 CloseHandle( handle );
121 SetLastError( ERROR_TOO_MANY_OPEN_FILES );
122 return HFILE_ERROR;
125 /***********************************************************************
126 * DisposeLZ32Handle (KERNEL32.22)
128 * Note: this is not entirely correct, we should only close the
129 * 32-bit handle and not the 16-bit one, but we cannot do
130 * this because of the way our DOS handles are implemented.
131 * It shouldn't break anything though.
133 void WINAPI DisposeLZ32Handle( HANDLE handle )
135 int i;
137 if (!handle || (handle == INVALID_HANDLE_VALUE)) return;
139 for (i = 5; i < DOS_TABLE_SIZE; i++)
140 if (dos_handles[i] == handle)
142 dos_handles[i] = 0;
143 CloseHandle( handle );
144 break;
148 /***********************************************************************
149 * GetProfileInt (KERNEL.57)
151 UINT16 WINAPI GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val )
153 return GetPrivateProfileInt16( section, entry, def_val, "win.ini" );
157 /***********************************************************************
158 * GetProfileString (KERNEL.58)
160 INT16 WINAPI GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
161 LPSTR buffer, UINT16 len )
163 return GetPrivateProfileString16( section, entry, def_val,
164 buffer, len, "win.ini" );
168 /***********************************************************************
169 * WriteProfileString (KERNEL.59)
171 BOOL16 WINAPI WriteProfileString16( LPCSTR section, LPCSTR entry,
172 LPCSTR string )
174 return WritePrivateProfileString16( section, entry, string, "win.ini" );
178 /* get the search path for the current module; helper for OpenFile16 */
179 static char *get_search_path(void)
181 UINT len;
182 char *ret, *p, module[OFS_MAXPATHNAME];
184 module[0] = 0;
185 if (GetCurrentTask() && GetModuleFileName16( GetCurrentTask(), module, sizeof(module) ))
187 if (!(p = strrchr( module, '\\' ))) p = module;
188 *p = 0;
191 len = (2 + /* search order: first current dir */
192 GetSystemDirectory16( NULL, 0 ) + 1 + /* then system dir */
193 GetWindowsDirectoryA( NULL, 0 ) + 1 + /* then windows dir */
194 strlen( module ) + 1 + /* then module path */
195 GetEnvironmentVariableA( "PATH", NULL, 0 ) + 1); /* then look in PATH */
196 if (!(ret = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
197 strcpy( ret, ".;" );
198 p = ret + 2;
199 GetSystemDirectory16( p, ret + len - p );
200 p += strlen( p );
201 *p++ = ';';
202 GetWindowsDirectoryA( p, ret + len - p );
203 p += strlen( p );
204 *p++ = ';';
205 if (module[0])
207 strcpy( p, module );
208 p += strlen( p );
209 *p++ = ';';
211 GetEnvironmentVariableA( "PATH", p, ret + len - p );
212 return ret;
215 /***********************************************************************
216 * OpenFile (KERNEL.74)
217 * OpenFileEx (KERNEL.360)
219 HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
221 HFILE hFileRet;
222 HANDLE handle;
223 FILETIME filetime;
224 WORD filedatetime[2];
225 const char *p, *filename;
227 if (!ofs) return HFILE_ERROR;
229 TRACE("%s %s %s %s%s%s%s%s%s%s%s%s\n",debugstr_a(name),
230 ((mode & 0x3 )==OF_READ)?"OF_READ":
231 ((mode & 0x3 )==OF_WRITE)?"OF_WRITE":
232 ((mode & 0x3 )==OF_READWRITE)?"OF_READWRITE":"unknown",
233 ((mode & 0x70 )==OF_SHARE_COMPAT)?"OF_SHARE_COMPAT":
234 ((mode & 0x70 )==OF_SHARE_DENY_NONE)?"OF_SHARE_DENY_NONE":
235 ((mode & 0x70 )==OF_SHARE_DENY_READ)?"OF_SHARE_DENY_READ":
236 ((mode & 0x70 )==OF_SHARE_DENY_WRITE)?"OF_SHARE_DENY_WRITE":
237 ((mode & 0x70 )==OF_SHARE_EXCLUSIVE)?"OF_SHARE_EXCLUSIVE":"unknown",
238 ((mode & OF_PARSE )==OF_PARSE)?"OF_PARSE ":"",
239 ((mode & OF_DELETE )==OF_DELETE)?"OF_DELETE ":"",
240 ((mode & OF_VERIFY )==OF_VERIFY)?"OF_VERIFY ":"",
241 ((mode & OF_SEARCH )==OF_SEARCH)?"OF_SEARCH ":"",
242 ((mode & OF_CANCEL )==OF_CANCEL)?"OF_CANCEL ":"",
243 ((mode & OF_CREATE )==OF_CREATE)?"OF_CREATE ":"",
244 ((mode & OF_PROMPT )==OF_PROMPT)?"OF_PROMPT ":"",
245 ((mode & OF_EXIST )==OF_EXIST)?"OF_EXIST ":"",
246 ((mode & OF_REOPEN )==OF_REOPEN)?"OF_REOPEN ":""
249 if (mode & OF_PARSE)
251 OpenFile( name, ofs, mode );
252 return 0;
255 if (mode & OF_CREATE)
257 handle = (HANDLE)OpenFile( name, ofs, mode );
258 if (handle == (HANDLE)HFILE_ERROR) goto error;
260 else
262 ofs->cBytes = sizeof(OFSTRUCT);
263 ofs->nErrCode = 0;
264 if (mode & OF_REOPEN) name = ofs->szPathName;
266 if (!name) return HFILE_ERROR;
268 /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
269 Are there any cases where getting the path here is wrong?
270 Uwe Bonnes 1997 Apr 2 */
271 if (!GetFullPathNameA( name, sizeof(ofs->szPathName), ofs->szPathName, NULL )) goto error;
273 /* If OF_SEARCH is set, ignore the given path */
275 filename = name;
276 if ((mode & OF_SEARCH) && !(mode & OF_REOPEN))
278 /* First try the file name as is */
279 if (GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES) filename = NULL;
280 else
282 /* Now remove the path */
283 if (filename[0] && (filename[1] == ':')) filename += 2;
284 if ((p = strrchr( filename, '\\' ))) filename = p + 1;
285 if ((p = strrchr( filename, '/' ))) filename = p + 1;
286 if (!filename[0])
288 SetLastError( ERROR_FILE_NOT_FOUND );
289 goto error;
294 /* Now look for the file */
296 if (filename)
298 BOOL found;
299 char *path = get_search_path();
301 if (!path) goto error;
302 found = SearchPathA( path, filename, NULL, sizeof(ofs->szPathName),
303 ofs->szPathName, NULL );
304 HeapFree( GetProcessHeap(), 0, path );
305 if (!found) goto error;
308 TRACE("found %s\n", debugstr_a(ofs->szPathName) );
310 if (mode & OF_DELETE)
312 if (!DeleteFileA( ofs->szPathName )) goto error;
313 TRACE("(%s): OF_DELETE return = OK\n", name);
314 return 1;
317 handle = (HANDLE)_lopen( ofs->szPathName, mode );
318 if (handle == INVALID_HANDLE_VALUE) goto error;
320 GetFileTime( handle, NULL, NULL, &filetime );
321 FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] );
322 if ((mode & OF_VERIFY) && (mode & OF_REOPEN))
324 if (ofs->Reserved1 != filedatetime[0] || ofs->Reserved2 != filedatetime[1] )
326 CloseHandle( handle );
327 WARN("(%s): OF_VERIFY failed\n", name );
328 /* FIXME: what error here? */
329 SetLastError( ERROR_FILE_NOT_FOUND );
330 goto error;
333 ofs->Reserved1 = filedatetime[0];
334 ofs->Reserved2 = filedatetime[1];
337 TRACE("(%s): OK, return = %p\n", name, handle );
338 hFileRet = Win32HandleToDosFileHandle( handle );
339 if (hFileRet == HFILE_ERROR16) goto error;
340 if (mode & OF_EXIST) _lclose16( hFileRet ); /* Return the handle, but close it first */
341 return hFileRet;
343 error: /* We get here if there was an error opening the file */
344 ofs->nErrCode = GetLastError();
345 WARN("(%s): return = HFILE_ERROR error= %d\n", name,ofs->nErrCode );
346 return HFILE_ERROR16;
350 /***********************************************************************
351 * _lclose (KERNEL.81)
353 HFILE16 WINAPI _lclose16( HFILE16 hFile )
355 if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile])
357 SetLastError( ERROR_INVALID_HANDLE );
358 return HFILE_ERROR16;
360 TRACE("%d (handle32=%p)\n", hFile, dos_handles[hFile] );
361 CloseHandle( dos_handles[hFile] );
362 dos_handles[hFile] = 0;
363 return 0;
366 /***********************************************************************
367 * _lcreat (KERNEL.83)
369 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
371 return Win32HandleToDosFileHandle( (HANDLE)_lcreat( path, attr ) );
374 /***********************************************************************
375 * _llseek (KERNEL.84)
377 * FIXME:
378 * Seeking before the start of the file should be allowed for _llseek16,
379 * but cause subsequent I/O operations to fail (cf. interrupt list)
382 LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
384 return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin );
388 /***********************************************************************
389 * _lopen (KERNEL.85)
391 HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
393 return Win32HandleToDosFileHandle( (HANDLE)_lopen( path, mode ) );
397 /***********************************************************************
398 * _lread16 (internal)
400 UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
402 return (UINT16)_lread((HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
406 /***********************************************************************
407 * _lwrite (KERNEL.86)
409 UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
411 return (UINT16)_hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
414 /***********************************************************************
415 * _hread (KERNEL.349)
417 LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
419 LONG maxlen;
421 TRACE("%d %08lx %ld\n", hFile, (DWORD)buffer, count );
423 /* Some programs pass a count larger than the allocated buffer */
424 maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
425 if (count > maxlen) count = maxlen;
426 return _lread((HFILE)DosFileHandleToWin32Handle(hFile), MapSL(buffer), count );
430 /***********************************************************************
431 * _lread (KERNEL.82)
433 UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
435 return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
439 /***********************************************************************
440 * _hwrite (KERNEL.350)
442 LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
444 return _hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
448 /***********************************************************************
449 * GetTempDrive (KERNEL.92)
450 * A closer look at krnl386.exe shows what the SDK doesn't mention:
452 * returns:
453 * AL: driveletter
454 * AH: ':' - yes, some kernel code even does stosw with
455 * the returned AX.
456 * DX: 1 for success
458 UINT WINAPI GetTempDrive( BYTE ignored )
460 WCHAR buffer[MAX_PATH];
461 BYTE ret = 'C';
463 if (GetTempPathW( MAX_PATH, buffer ))
465 ret = buffer[0];
466 if (ret >= 'a' && ret <= 'z') ret += 'A' - 'a';
468 return MAKELONG( ret | (':' << 8), 1 );
472 /***********************************************************************
473 * GetTempFileName (KERNEL.97)
475 UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
476 LPSTR buffer )
478 char temppath[MAX_PATH];
479 char *prefix16 = NULL;
480 UINT16 ret;
482 if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */
484 GetCurrentDirectoryA(sizeof(temppath), temppath);
485 drive |= temppath[0];
488 if (drive & TF_FORCEDRIVE)
490 char d[3];
492 d[0] = drive & ~TF_FORCEDRIVE;
493 d[1] = ':';
494 d[2] = '\0';
495 if (GetDriveTypeA(d) == DRIVE_NO_ROOT_DIR)
497 drive &= ~TF_FORCEDRIVE;
498 WARN("invalid drive %d specified\n", drive );
502 if (drive & TF_FORCEDRIVE)
503 sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE );
504 else
505 GetTempPathA( MAX_PATH, temppath );
507 if (prefix)
509 prefix16 = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + 2);
510 *prefix16 = '~';
511 strcpy(prefix16 + 1, prefix);
514 ret = GetTempFileNameA( temppath, prefix16, unique, buffer );
516 HeapFree(GetProcessHeap(), 0, prefix16);
517 return ret;
521 /***********************************************************************
522 * GetPrivateProfileInt (KERNEL.127)
524 UINT16 WINAPI GetPrivateProfileInt16( LPCSTR section, LPCSTR entry,
525 INT16 def_val, LPCSTR filename )
527 /* we used to have some elaborate return value limitation (<= -32768 etc.)
528 * here, but Win98SE doesn't care about this at all, so I deleted it.
529 * AFAIR versions prior to Win9x had these limits, though. */
530 return (INT16)GetPrivateProfileIntA(section,entry,def_val,filename);
534 /***********************************************************************
535 * GetPrivateProfileString (KERNEL.128)
537 INT16 WINAPI GetPrivateProfileString16( LPCSTR section, LPCSTR entry,
538 LPCSTR def_val, LPSTR buffer,
539 UINT16 len, LPCSTR filename )
541 TRACE("(%s, %s, %s, %p, %u, %s)\n", debugstr_a(section), debugstr_a(entry),
542 debugstr_a(def_val), buffer, len, debugstr_a(filename));
544 if (!section)
546 if (buffer && len) buffer[0] = 0;
547 return 0;
549 if (!entry)
551 /* We have to return the list of keys in the section but without the values
552 * so we need to massage the results of GetPrivateProfileSectionA.
554 UINT ret, oldlen = len, size = min( len, 1024 );
555 LPSTR data, src;
557 for (;;)
559 if (!(data = HeapAlloc(GetProcessHeap(), 0, size ))) return 0;
560 ret = GetPrivateProfileSectionA( section, data, size, filename );
561 if (!ret)
563 HeapFree( GetProcessHeap(), 0, data );
564 return GetPrivateProfileStringA( section, entry, def_val, buffer, len, filename );
566 if (ret != size - 2) break;
567 /* overflow, try again */
568 size *= 2;
569 HeapFree( GetProcessHeap(), 0, data );
572 src = data;
573 while (len && *src)
575 char *p = strchr( src, '=' );
577 /* A valid entry is formed by name = value */
578 if (!p)
580 src += strlen(src) + 1;
581 continue;
583 if (p - src < len)
585 memcpy( buffer, src, p - src );
586 buffer += p - src;
587 *buffer++ = 0;
588 len -= (p - src) + 1;
589 src += strlen(src) + 1;
591 else /* overflow */
593 memcpy( buffer, src, len );
594 buffer += len;
595 len = 0;
598 HeapFree( GetProcessHeap(), 0, data );
600 if (len)
602 *buffer = 0;
603 return oldlen - len;
605 if (oldlen > 2)
607 buffer[-2] = 0;
608 buffer[-1] = 0;
609 return oldlen - 2;
611 return 0;
613 return GetPrivateProfileStringA( section, entry, def_val, buffer, len, filename );
617 /***********************************************************************
618 * WritePrivateProfileString (KERNEL.129)
620 BOOL16 WINAPI WritePrivateProfileString16( LPCSTR section, LPCSTR entry,
621 LPCSTR string, LPCSTR filename )
623 return WritePrivateProfileStringA(section,entry,string,filename);
627 /***********************************************************************
628 * GetWindowsDirectory (KERNEL.134)
630 UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count )
632 return GetWindowsDirectoryA( path, count );
636 /***********************************************************************
637 * GetSystemDirectory (KERNEL.135)
639 UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count )
641 static const char system16[] = "\\SYSTEM";
642 char windir[MAX_PATH];
643 UINT16 len;
645 len = GetWindowsDirectory16(windir, sizeof(windir) - sizeof(system16) + 1) + sizeof(system16);
646 if (count >= len)
648 lstrcpyA(path, windir);
649 lstrcatA(path, system16);
650 len--; /* space for the terminating zero is not included on success */
652 return len;
656 /***********************************************************************
657 * GetDriveType (KERNEL.136)
658 * Get the type of a drive in Win16.
660 * RETURNS
661 * The type of the Drive. For a list see GetDriveTypeW from kernel32.
663 * NOTES
664 * Note that it returns DRIVE_REMOTE for CD-ROMs, since MSCDEX uses the
665 * remote drive API. The return value DRIVE_REMOTE for CD-ROMs has been
666 * verified on Win 3.11 and Windows 95. Some programs rely on it, so don't
667 * do any pseudo-clever changes.
669 UINT16 WINAPI GetDriveType16( UINT16 drive ) /* [in] number (NOT letter) of drive */
671 UINT type;
672 WCHAR root[3];
674 root[0] = 'A' + drive;
675 root[1] = ':';
676 root[2] = 0;
677 type = GetDriveTypeW( root );
678 if (type == DRIVE_CDROM) type = DRIVE_REMOTE;
679 else if (type == DRIVE_NO_ROOT_DIR) type = DRIVE_UNKNOWN;
680 return type;
684 /***********************************************************************
685 * GetProfileSectionNames (KERNEL.142)
687 WORD WINAPI GetProfileSectionNames16(LPSTR buffer, WORD size)
690 return GetPrivateProfileSectionNamesA(buffer,size,"win.ini");
694 /***********************************************************************
695 * GetPrivateProfileSectionNames (KERNEL.143)
697 WORD WINAPI GetPrivateProfileSectionNames16( LPSTR buffer, WORD size,
698 LPCSTR filename )
700 return GetPrivateProfileSectionNamesA(buffer,size,filename);
704 /***********************************************************************
705 * CreateDirectory (KERNEL.144)
707 BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy )
709 return CreateDirectoryA( path, NULL );
713 /***********************************************************************
714 * RemoveDirectory (KERNEL.145)
716 BOOL16 WINAPI RemoveDirectory16( LPCSTR path )
718 return RemoveDirectoryA( path );
722 /***********************************************************************
723 * DeleteFile (KERNEL.146)
725 BOOL16 WINAPI DeleteFile16( LPCSTR path )
727 return DeleteFileA( path );
731 /***********************************************************************
732 * SetHandleCount (KERNEL.199)
734 UINT16 WINAPI SetHandleCount16( UINT16 count )
736 return SetHandleCount( count );
740 /***********************************************************************
741 * GetShortPathName (KERNEL.274)
743 WORD WINAPI GetShortPathName16( LPCSTR longpath, LPSTR shortpath, WORD len )
745 return GetShortPathNameA( longpath, shortpath, len );
749 /***********************************************************************
750 * WriteOutProfiles (KERNEL.315)
752 void WINAPI WriteOutProfiles16(void)
754 WritePrivateProfileSectionW( NULL, NULL, NULL );
758 /***********************************************************************
759 * WritePrivateProfileStruct (KERNEL.406)
761 BOOL16 WINAPI WritePrivateProfileStruct16 (LPCSTR section, LPCSTR key,
762 LPVOID buf, UINT16 bufsize, LPCSTR filename)
764 return WritePrivateProfileStructA( section, key, buf, bufsize, filename );
768 /***********************************************************************
769 * GetPrivateProfileStruct (KERNEL.407)
771 BOOL16 WINAPI GetPrivateProfileStruct16(LPCSTR section, LPCSTR key,
772 LPVOID buf, UINT16 len, LPCSTR filename)
774 return GetPrivateProfileStructA( section, key, buf, len, filename );
778 /***********************************************************************
779 * GetCurrentDirectory (KERNEL.411)
781 UINT16 WINAPI GetCurrentDirectory16( UINT16 buflen, LPSTR buf )
783 return GetCurrentDirectoryA( buflen, buf );
787 /***********************************************************************
788 * SetCurrentDirectory (KERNEL.412)
790 BOOL16 WINAPI SetCurrentDirectory16( LPCSTR dir )
792 char fulldir[MAX_PATH];
794 if (!GetFullPathNameA( dir, MAX_PATH, fulldir, NULL )) return FALSE;
796 if (!SetCurrentDirectoryA( dir )) return FALSE;
798 if (fulldir[0] && fulldir[1] == ':')
800 TDB *pTask = GlobalLock16( GetCurrentTask() );
801 char env_var[4] = "=A:";
803 env_var[1] = fulldir[0];
804 SetEnvironmentVariableA( env_var, fulldir );
806 /* update the directory in the TDB */
807 if (pTask)
809 pTask->curdrive = 0x80 | (fulldir[0] - 'A');
810 GetShortPathNameA( fulldir + 2, pTask->curdir, sizeof(pTask->curdir) );
813 return TRUE;
817 /*************************************************************************
818 * FindFirstFile (KERNEL.413)
820 HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATAA *data )
822 HGLOBAL16 h16;
823 HANDLE handle, *ptr;
825 if (!(h16 = GlobalAlloc16( GMEM_MOVEABLE, sizeof(handle) ))) return INVALID_HANDLE_VALUE16;
826 ptr = GlobalLock16( h16 );
827 *ptr = handle = FindFirstFileA( path, data );
828 GlobalUnlock16( h16 );
830 if (handle == INVALID_HANDLE_VALUE)
832 GlobalFree16( h16 );
833 h16 = INVALID_HANDLE_VALUE16;
835 return h16;
839 /*************************************************************************
840 * FindNextFile (KERNEL.414)
842 BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATAA *data )
844 HANDLE *ptr;
845 BOOL ret = FALSE;
847 if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle )))
849 SetLastError( ERROR_INVALID_HANDLE );
850 return ret;
852 ret = FindNextFileA( *ptr, data );
853 GlobalUnlock16( handle );
854 return ret;
858 /*************************************************************************
859 * FindClose (KERNEL.415)
861 BOOL16 WINAPI FindClose16( HANDLE16 handle )
863 HANDLE *ptr;
865 if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle )))
867 SetLastError( ERROR_INVALID_HANDLE );
868 return FALSE;
870 FindClose( *ptr );
871 GlobalUnlock16( handle );
872 GlobalFree16( handle );
873 return TRUE;
877 /***********************************************************************
878 * WritePrivateProfileSection (KERNEL.416)
880 BOOL16 WINAPI WritePrivateProfileSection16( LPCSTR section,
881 LPCSTR string, LPCSTR filename )
883 return WritePrivateProfileSectionA( section, string, filename );
887 /***********************************************************************
888 * WriteProfileSection (KERNEL.417)
890 BOOL16 WINAPI WriteProfileSection16( LPCSTR section, LPCSTR keys_n_values)
892 return WritePrivateProfileSection16( section, keys_n_values, "win.ini");
896 /***********************************************************************
897 * GetPrivateProfileSection (KERNEL.418)
899 INT16 WINAPI GetPrivateProfileSection16( LPCSTR section, LPSTR buffer,
900 UINT16 len, LPCSTR filename )
902 return GetPrivateProfileSectionA( section, buffer, len, filename );
906 /***********************************************************************
907 * GetProfileSection (KERNEL.419)
909 INT16 WINAPI GetProfileSection16( LPCSTR section, LPSTR buffer, UINT16 len )
911 return GetPrivateProfileSection16( section, buffer, len, "win.ini" );
915 /**************************************************************************
916 * GetFileAttributes (KERNEL.420)
918 DWORD WINAPI GetFileAttributes16( LPCSTR name )
920 return GetFileAttributesA( name );
924 /**************************************************************************
925 * SetFileAttributes (KERNEL.421)
927 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
929 return SetFileAttributesA( lpFileName, attributes );
933 /***********************************************************************
934 * GetDiskFreeSpace (KERNEL.422)
936 BOOL16 WINAPI GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors,
937 LPDWORD sector_bytes, LPDWORD free_clusters,
938 LPDWORD total_clusters )
940 return GetDiskFreeSpaceA( root, cluster_sectors, sector_bytes,
941 free_clusters, total_clusters );
944 /***********************************************************************
945 * FileCDR (KERNEL.130)
947 FARPROC16 WINAPI FileCDR16(FARPROC16 x)
949 FIXME("(%p): stub\n", x);
950 return (FARPROC16)TRUE;