shell32/autocomplete: Reduce the strlen calls because they are redundant.
[wine.git] / dlls / krnl386.exe16 / file.c
blob4e7f7c4b33a132fd7fe8ddcf6ba67daa37555abf
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 "config.h"
27 #include "wine/port.h"
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <assert.h>
33 #include "winerror.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winternl.h"
37 #include "wine/winbase16.h"
38 #include "kernel16_private.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(file);
44 #define DOS_TABLE_SIZE 256
46 static HANDLE dos_handles[DOS_TABLE_SIZE];
48 /***********************************************************************
49 * FILE_InitProcessDosHandles
51 * Allocates the default DOS handles for a process. Called either by
52 * Win32HandleToDosFileHandle below or by the DOSVM stuff.
54 static void FILE_InitProcessDosHandles( void )
56 HANDLE hStdInput, hStdOutput, hStdError, hNull;
57 static BOOL init_done /* = FALSE */;
58 HANDLE cp = GetCurrentProcess();
60 if (init_done) return;
61 init_done = TRUE;
62 hStdInput = GetStdHandle(STD_INPUT_HANDLE);
63 hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
64 hStdError = GetStdHandle(STD_ERROR_HANDLE);
65 hNull = CreateFileA("NUL", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
66 /* Invalid console handles need to translate to real DOS handles in a new process */
67 if (!hStdInput) hStdInput = hNull;
68 if (!hStdOutput) hStdOutput = hNull;
69 if (!hStdError) hStdError = hNull;
70 DuplicateHandle(cp, hStdInput, cp, &dos_handles[0], 0, TRUE, DUPLICATE_SAME_ACCESS);
71 DuplicateHandle(cp, hStdOutput, cp, &dos_handles[1], 0, TRUE, DUPLICATE_SAME_ACCESS);
72 DuplicateHandle(cp, hStdError, cp, &dos_handles[2], 0, TRUE, DUPLICATE_SAME_ACCESS);
73 DuplicateHandle(cp, hStdError, cp, &dos_handles[3], 0, TRUE, DUPLICATE_SAME_ACCESS);
74 DuplicateHandle(cp, hStdError, cp, &dos_handles[4], 0, TRUE, DUPLICATE_SAME_ACCESS);
75 CloseHandle(hNull);
78 /***********************************************************************
79 * DosFileHandleToWin32Handle (KERNEL32.20)
81 * Return the Win32 handle for a DOS handle.
83 * Note: this is not exactly right, since on Win95 the Win32 handles
84 * are on top of DOS handles and we do it the other way
85 * around. Should be good enough though.
87 HANDLE WINAPI DosFileHandleToWin32Handle( HFILE handle )
89 HFILE16 hfile = (HFILE16)handle;
90 if (hfile < 5) FILE_InitProcessDosHandles();
91 if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile])
93 SetLastError( ERROR_INVALID_HANDLE );
94 return INVALID_HANDLE_VALUE;
96 return dos_handles[hfile];
99 /***********************************************************************
100 * Win32HandleToDosFileHandle (KERNEL32.21)
102 * Allocate a DOS handle for a Win32 handle. The Win32 handle is no
103 * longer valid after this function (even on failure).
105 * Note: this is not exactly right, since on Win95 the Win32 handles
106 * are on top of DOS handles and we do it the other way
107 * around. Should be good enough though.
109 HFILE WINAPI Win32HandleToDosFileHandle( HANDLE handle )
111 int i;
113 if (!handle || (handle == INVALID_HANDLE_VALUE))
114 return HFILE_ERROR;
116 for (i = 5; i < DOS_TABLE_SIZE; i++)
117 if (!dos_handles[i])
119 dos_handles[i] = handle;
120 TRACE("Got %d for h32 %p\n", i, handle );
121 return (HFILE)i;
123 CloseHandle( handle );
124 SetLastError( ERROR_TOO_MANY_OPEN_FILES );
125 return HFILE_ERROR;
128 /***********************************************************************
129 * DisposeLZ32Handle (KERNEL32.22)
131 * Note: this is not entirely correct, we should only close the
132 * 32-bit handle and not the 16-bit one, but we cannot do
133 * this because of the way our DOS handles are implemented.
134 * It shouldn't break anything though.
136 void WINAPI DisposeLZ32Handle( HANDLE handle )
138 int i;
140 if (!handle || (handle == INVALID_HANDLE_VALUE)) return;
142 for (i = 5; i < DOS_TABLE_SIZE; i++)
143 if (dos_handles[i] == handle)
145 dos_handles[i] = 0;
146 CloseHandle( handle );
147 break;
151 /***********************************************************************
152 * GetProfileInt (KERNEL.57)
154 UINT16 WINAPI GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val )
156 return GetPrivateProfileInt16( section, entry, def_val, "win.ini" );
160 /***********************************************************************
161 * GetProfileString (KERNEL.58)
163 INT16 WINAPI GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
164 LPSTR buffer, UINT16 len )
166 return GetPrivateProfileString16( section, entry, def_val,
167 buffer, len, "win.ini" );
171 /***********************************************************************
172 * WriteProfileString (KERNEL.59)
174 BOOL16 WINAPI WriteProfileString16( LPCSTR section, LPCSTR entry,
175 LPCSTR string )
177 return WritePrivateProfileString16( section, entry, string, "win.ini" );
181 /* get the search path for the current module; helper for OpenFile16 */
182 static char *get_search_path(void)
184 UINT len;
185 char *ret, *p, module[OFS_MAXPATHNAME];
187 module[0] = 0;
188 if (GetCurrentTask() && GetModuleFileName16( GetCurrentTask(), module, sizeof(module) ))
190 if (!(p = strrchr( module, '\\' ))) p = module;
191 *p = 0;
194 len = (2 + /* search order: first current dir */
195 GetSystemDirectory16( NULL, 0 ) + 1 + /* then system dir */
196 GetWindowsDirectoryA( NULL, 0 ) + 1 + /* then windows dir */
197 strlen( module ) + 1 + /* then module path */
198 GetEnvironmentVariableA( "PATH", NULL, 0 ) + 1); /* then look in PATH */
199 if (!(ret = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
200 strcpy( ret, ".;" );
201 p = ret + 2;
202 GetSystemDirectory16( p, ret + len - p );
203 p += strlen( p );
204 *p++ = ';';
205 GetWindowsDirectoryA( p, ret + len - p );
206 p += strlen( p );
207 *p++ = ';';
208 if (module[0])
210 strcpy( p, module );
211 p += strlen( p );
212 *p++ = ';';
214 GetEnvironmentVariableA( "PATH", p, ret + len - p );
215 return ret;
218 /***********************************************************************
219 * OpenFile (KERNEL.74)
220 * OpenFileEx (KERNEL.360)
222 HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
224 HFILE hFileRet;
225 HANDLE handle;
226 FILETIME filetime;
227 WORD filedatetime[2];
228 const char *p, *filename;
230 if (!ofs) return HFILE_ERROR;
232 TRACE("%s %s %s %s%s%s%s%s%s%s%s%s\n",debugstr_a(name),
233 ((mode & 0x3 )==OF_READ)?"OF_READ":
234 ((mode & 0x3 )==OF_WRITE)?"OF_WRITE":
235 ((mode & 0x3 )==OF_READWRITE)?"OF_READWRITE":"unknown",
236 ((mode & 0x70 )==OF_SHARE_COMPAT)?"OF_SHARE_COMPAT":
237 ((mode & 0x70 )==OF_SHARE_DENY_NONE)?"OF_SHARE_DENY_NONE":
238 ((mode & 0x70 )==OF_SHARE_DENY_READ)?"OF_SHARE_DENY_READ":
239 ((mode & 0x70 )==OF_SHARE_DENY_WRITE)?"OF_SHARE_DENY_WRITE":
240 ((mode & 0x70 )==OF_SHARE_EXCLUSIVE)?"OF_SHARE_EXCLUSIVE":"unknown",
241 ((mode & OF_PARSE )==OF_PARSE)?"OF_PARSE ":"",
242 ((mode & OF_DELETE )==OF_DELETE)?"OF_DELETE ":"",
243 ((mode & OF_VERIFY )==OF_VERIFY)?"OF_VERIFY ":"",
244 ((mode & OF_SEARCH )==OF_SEARCH)?"OF_SEARCH ":"",
245 ((mode & OF_CANCEL )==OF_CANCEL)?"OF_CANCEL ":"",
246 ((mode & OF_CREATE )==OF_CREATE)?"OF_CREATE ":"",
247 ((mode & OF_PROMPT )==OF_PROMPT)?"OF_PROMPT ":"",
248 ((mode & OF_EXIST )==OF_EXIST)?"OF_EXIST ":"",
249 ((mode & OF_REOPEN )==OF_REOPEN)?"OF_REOPEN ":""
252 if (mode & OF_PARSE)
254 OpenFile( name, ofs, mode );
255 return 0;
258 if (mode & OF_CREATE)
260 handle = (HANDLE)OpenFile( name, ofs, mode );
261 if (handle == (HANDLE)HFILE_ERROR) goto error;
263 else
265 ofs->cBytes = sizeof(OFSTRUCT);
266 ofs->nErrCode = 0;
267 if (mode & OF_REOPEN) name = ofs->szPathName;
269 if (!name) return HFILE_ERROR;
271 /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
272 Are there any cases where getting the path here is wrong?
273 Uwe Bonnes 1997 Apr 2 */
274 if (!GetFullPathNameA( name, sizeof(ofs->szPathName), ofs->szPathName, NULL )) goto error;
276 /* If OF_SEARCH is set, ignore the given path */
278 filename = name;
279 if ((mode & OF_SEARCH) && !(mode & OF_REOPEN))
281 /* First try the file name as is */
282 if (GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES) filename = NULL;
283 else
285 /* Now remove the path */
286 if (filename[0] && (filename[1] == ':')) filename += 2;
287 if ((p = strrchr( filename, '\\' ))) filename = p + 1;
288 if ((p = strrchr( filename, '/' ))) filename = p + 1;
289 if (!filename[0])
291 SetLastError( ERROR_FILE_NOT_FOUND );
292 goto error;
297 /* Now look for the file */
299 if (filename)
301 BOOL found;
302 char *path = get_search_path();
304 if (!path) goto error;
305 found = SearchPathA( path, filename, NULL, sizeof(ofs->szPathName),
306 ofs->szPathName, NULL );
307 HeapFree( GetProcessHeap(), 0, path );
308 if (!found) goto error;
311 TRACE("found %s\n", debugstr_a(ofs->szPathName) );
313 if (mode & OF_DELETE)
315 if (!DeleteFileA( ofs->szPathName )) goto error;
316 TRACE("(%s): OF_DELETE return = OK\n", name);
317 return 1;
320 handle = (HANDLE)_lopen( ofs->szPathName, mode );
321 if (handle == INVALID_HANDLE_VALUE) goto error;
323 GetFileTime( handle, NULL, NULL, &filetime );
324 FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] );
325 if ((mode & OF_VERIFY) && (mode & OF_REOPEN))
327 if (ofs->Reserved1 != filedatetime[0] || ofs->Reserved2 != filedatetime[1] )
329 CloseHandle( handle );
330 WARN("(%s): OF_VERIFY failed\n", name );
331 /* FIXME: what error here? */
332 SetLastError( ERROR_FILE_NOT_FOUND );
333 goto error;
336 ofs->Reserved1 = filedatetime[0];
337 ofs->Reserved2 = filedatetime[1];
340 TRACE("(%s): OK, return = %p\n", name, handle );
341 hFileRet = Win32HandleToDosFileHandle( handle );
342 if (hFileRet == HFILE_ERROR16) goto error;
343 if (mode & OF_EXIST) _lclose16( hFileRet ); /* Return the handle, but close it first */
344 return hFileRet;
346 error: /* We get here if there was an error opening the file */
347 ofs->nErrCode = GetLastError();
348 WARN("(%s): return = HFILE_ERROR error= %d\n", name,ofs->nErrCode );
349 return HFILE_ERROR16;
353 /***********************************************************************
354 * _lclose (KERNEL.81)
356 HFILE16 WINAPI _lclose16( HFILE16 hFile )
358 if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile])
360 SetLastError( ERROR_INVALID_HANDLE );
361 return HFILE_ERROR16;
363 TRACE("%d (handle32=%p)\n", hFile, dos_handles[hFile] );
364 CloseHandle( dos_handles[hFile] );
365 dos_handles[hFile] = 0;
366 return 0;
369 /***********************************************************************
370 * _lcreat (KERNEL.83)
372 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
374 return Win32HandleToDosFileHandle( (HANDLE)_lcreat( path, attr ) );
377 /***********************************************************************
378 * _llseek (KERNEL.84)
380 * FIXME:
381 * Seeking before the start of the file should be allowed for _llseek16,
382 * but cause subsequent I/O operations to fail (cf. interrupt list)
385 LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
387 return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin );
391 /***********************************************************************
392 * _lopen (KERNEL.85)
394 HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
396 return Win32HandleToDosFileHandle( (HANDLE)_lopen( path, mode ) );
400 /***********************************************************************
401 * _lread16 (internal)
403 UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
405 return (UINT16)_lread((HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
409 /***********************************************************************
410 * _lwrite (KERNEL.86)
412 UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
414 return (UINT16)_hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
417 /***********************************************************************
418 * _hread (KERNEL.349)
420 LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
422 LONG maxlen;
424 TRACE("%d %08x %d\n", hFile, (DWORD)buffer, count );
426 /* Some programs pass a count larger than the allocated buffer */
427 maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
428 if (count > maxlen) count = maxlen;
429 return _lread((HFILE)DosFileHandleToWin32Handle(hFile), MapSL(buffer), count );
433 /***********************************************************************
434 * _lread (KERNEL.82)
436 UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
438 return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
442 /***********************************************************************
443 * _hwrite (KERNEL.350)
445 LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
447 return _hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
451 /***********************************************************************
452 * GetTempDrive (KERNEL.92)
453 * A closer look at krnl386.exe shows what the SDK doesn't mention:
455 * returns:
456 * AL: driveletter
457 * AH: ':' - yes, some kernel code even does stosw with
458 * the returned AX.
459 * DX: 1 for success
461 UINT WINAPI GetTempDrive( BYTE ignored )
463 WCHAR buffer[MAX_PATH];
464 BYTE ret;
466 if (GetTempPathW( MAX_PATH, buffer )) ret = (BYTE)toupperW(buffer[0]);
467 else ret = 'C';
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;