kernel32: Update Italian translation.
[wine/testsucceed.git] / dlls / krnl386.exe16 / file.c
blob507b28d4fa69f737a6dd0a496d79d477f33f340a
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 #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"
40 #include "kernel16_private.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(file);
46 #define DOS_TABLE_SIZE 256
48 static HANDLE dos_handles[DOS_TABLE_SIZE];
50 /***********************************************************************
51 * FILE_InitProcessDosHandles
53 * Allocates the default DOS handles for a process. Called either by
54 * Win32HandleToDosFileHandle below or by the DOSVM stuff.
56 static void FILE_InitProcessDosHandles( void )
58 static BOOL init_done /* = FALSE */;
59 HANDLE cp = GetCurrentProcess();
61 if (init_done) return;
62 init_done = TRUE;
63 DuplicateHandle(cp, GetStdHandle(STD_INPUT_HANDLE), cp, &dos_handles[0],
64 0, TRUE, DUPLICATE_SAME_ACCESS);
65 DuplicateHandle(cp, GetStdHandle(STD_OUTPUT_HANDLE), cp, &dos_handles[1],
66 0, TRUE, DUPLICATE_SAME_ACCESS);
67 DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[2],
68 0, TRUE, DUPLICATE_SAME_ACCESS);
69 DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[3],
70 0, TRUE, DUPLICATE_SAME_ACCESS);
71 DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[4],
72 0, TRUE, DUPLICATE_SAME_ACCESS);
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 FILE_InitProcessDosHandles();
114 for (i = 0; i < DOS_TABLE_SIZE; i++)
115 if (!dos_handles[i])
117 dos_handles[i] = handle;
118 TRACE("Got %d for h32 %p\n", i, handle );
119 return (HFILE)i;
121 CloseHandle( handle );
122 SetLastError( ERROR_TOO_MANY_OPEN_FILES );
123 return HFILE_ERROR;
126 /***********************************************************************
127 * DisposeLZ32Handle (KERNEL32.22)
129 * Note: this is not entirely correct, we should only close the
130 * 32-bit handle and not the 16-bit one, but we cannot do
131 * this because of the way our DOS handles are implemented.
132 * It shouldn't break anything though.
134 void WINAPI DisposeLZ32Handle( HANDLE handle )
136 int i;
138 if (!handle || (handle == INVALID_HANDLE_VALUE)) return;
140 for (i = 5; i < DOS_TABLE_SIZE; i++)
141 if (dos_handles[i] == handle)
143 dos_handles[i] = 0;
144 CloseHandle( handle );
145 break;
149 /***********************************************************************
150 * GetProfileInt (KERNEL.57)
152 UINT16 WINAPI GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val )
154 return GetPrivateProfileInt16( section, entry, def_val, "win.ini" );
158 /***********************************************************************
159 * GetProfileString (KERNEL.58)
161 INT16 WINAPI GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
162 LPSTR buffer, UINT16 len )
164 return GetPrivateProfileString16( section, entry, def_val,
165 buffer, len, "win.ini" );
169 /***********************************************************************
170 * WriteProfileString (KERNEL.59)
172 BOOL16 WINAPI WriteProfileString16( LPCSTR section, LPCSTR entry,
173 LPCSTR string )
175 return WritePrivateProfileString16( section, entry, string, "win.ini" );
179 /* get the search path for the current module; helper for OpenFile16 */
180 static char *get_search_path(void)
182 UINT len;
183 char *ret, *p, module[OFS_MAXPATHNAME];
185 module[0] = 0;
186 if (GetCurrentTask() && GetModuleFileName16( GetCurrentTask(), module, sizeof(module) ))
188 if (!(p = strrchr( module, '\\' ))) p = module;
189 *p = 0;
192 len = (2 + /* search order: first current dir */
193 GetSystemDirectory16( NULL, 0 ) + 1 + /* then system dir */
194 GetWindowsDirectoryA( NULL, 0 ) + 1 + /* then windows dir */
195 strlen( module ) + 1 + /* then module path */
196 GetEnvironmentVariableA( "PATH", NULL, 0 ) + 1); /* then look in PATH */
197 if (!(ret = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
198 strcpy( ret, ".;" );
199 p = ret + 2;
200 GetSystemDirectory16( p, ret + len - p );
201 p += strlen( p );
202 *p++ = ';';
203 GetWindowsDirectoryA( p, ret + len - p );
204 p += strlen( p );
205 *p++ = ';';
206 if (module[0])
208 strcpy( p, module );
209 p += strlen( p );
210 *p++ = ';';
212 GetEnvironmentVariableA( "PATH", p, ret + len - p );
213 return ret;
216 /***********************************************************************
217 * OpenFile (KERNEL.74)
218 * OpenFileEx (KERNEL.360)
220 HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
222 HFILE hFileRet;
223 HANDLE handle;
224 FILETIME filetime;
225 WORD filedatetime[2];
226 const char *p, *filename;
228 if (!ofs) return HFILE_ERROR;
230 TRACE("%s %s %s %s%s%s%s%s%s%s%s%s\n",debugstr_a(name),
231 ((mode & 0x3 )==OF_READ)?"OF_READ":
232 ((mode & 0x3 )==OF_WRITE)?"OF_WRITE":
233 ((mode & 0x3 )==OF_READWRITE)?"OF_READWRITE":"unknown",
234 ((mode & 0x70 )==OF_SHARE_COMPAT)?"OF_SHARE_COMPAT":
235 ((mode & 0x70 )==OF_SHARE_DENY_NONE)?"OF_SHARE_DENY_NONE":
236 ((mode & 0x70 )==OF_SHARE_DENY_READ)?"OF_SHARE_DENY_READ":
237 ((mode & 0x70 )==OF_SHARE_DENY_WRITE)?"OF_SHARE_DENY_WRITE":
238 ((mode & 0x70 )==OF_SHARE_EXCLUSIVE)?"OF_SHARE_EXCLUSIVE":"unknown",
239 ((mode & OF_PARSE )==OF_PARSE)?"OF_PARSE ":"",
240 ((mode & OF_DELETE )==OF_DELETE)?"OF_DELETE ":"",
241 ((mode & OF_VERIFY )==OF_VERIFY)?"OF_VERIFY ":"",
242 ((mode & OF_SEARCH )==OF_SEARCH)?"OF_SEARCH ":"",
243 ((mode & OF_CANCEL )==OF_CANCEL)?"OF_CANCEL ":"",
244 ((mode & OF_CREATE )==OF_CREATE)?"OF_CREATE ":"",
245 ((mode & OF_PROMPT )==OF_PROMPT)?"OF_PROMPT ":"",
246 ((mode & OF_EXIST )==OF_EXIST)?"OF_EXIST ":"",
247 ((mode & OF_REOPEN )==OF_REOPEN)?"OF_REOPEN ":""
250 if (mode & OF_PARSE)
252 OpenFile( name, ofs, mode );
253 return 0;
256 if (mode & OF_CREATE)
258 handle = (HANDLE)OpenFile( name, ofs, mode );
259 if (handle == (HANDLE)HFILE_ERROR) goto error;
261 else
263 ofs->cBytes = sizeof(OFSTRUCT);
264 ofs->nErrCode = 0;
265 if (mode & OF_REOPEN) name = ofs->szPathName;
267 if (!name) return HFILE_ERROR;
269 /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
270 Are there any cases where getting the path here is wrong?
271 Uwe Bonnes 1997 Apr 2 */
272 if (!GetFullPathNameA( name, sizeof(ofs->szPathName), ofs->szPathName, NULL )) goto error;
274 /* If OF_SEARCH is set, ignore the given path */
276 filename = name;
277 if ((mode & OF_SEARCH) && !(mode & OF_REOPEN))
279 /* First try the file name as is */
280 if (GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES) filename = NULL;
281 else
283 /* Now remove the path */
284 if (filename[0] && (filename[1] == ':')) filename += 2;
285 if ((p = strrchr( filename, '\\' ))) filename = p + 1;
286 if ((p = strrchr( filename, '/' ))) filename = p + 1;
287 if (!filename[0])
289 SetLastError( ERROR_FILE_NOT_FOUND );
290 goto error;
295 /* Now look for the file */
297 if (filename)
299 BOOL found;
300 char *path = get_search_path();
302 if (!path) goto error;
303 found = SearchPathA( path, filename, NULL, sizeof(ofs->szPathName),
304 ofs->szPathName, NULL );
305 HeapFree( GetProcessHeap(), 0, path );
306 if (!found) goto error;
309 TRACE("found %s\n", debugstr_a(ofs->szPathName) );
311 if (mode & OF_DELETE)
313 if (!DeleteFileA( ofs->szPathName )) goto error;
314 TRACE("(%s): OF_DELETE return = OK\n", name);
315 return 1;
318 handle = (HANDLE)_lopen( ofs->szPathName, mode );
319 if (handle == INVALID_HANDLE_VALUE) goto error;
321 GetFileTime( handle, NULL, NULL, &filetime );
322 FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] );
323 if ((mode & OF_VERIFY) && (mode & OF_REOPEN))
325 if (ofs->Reserved1 != filedatetime[0] || ofs->Reserved2 != filedatetime[1] )
327 CloseHandle( handle );
328 WARN("(%s): OF_VERIFY failed\n", name );
329 /* FIXME: what error here? */
330 SetLastError( ERROR_FILE_NOT_FOUND );
331 goto error;
334 ofs->Reserved1 = filedatetime[0];
335 ofs->Reserved2 = filedatetime[1];
338 TRACE("(%s): OK, return = %p\n", name, handle );
339 hFileRet = Win32HandleToDosFileHandle( handle );
340 if (hFileRet == HFILE_ERROR16) goto error;
341 if (mode & OF_EXIST) _lclose16( hFileRet ); /* Return the handle, but close it first */
342 return hFileRet;
344 error: /* We get here if there was an error opening the file */
345 ofs->nErrCode = GetLastError();
346 WARN("(%s): return = HFILE_ERROR error= %d\n", name,ofs->nErrCode );
347 return HFILE_ERROR16;
351 /***********************************************************************
352 * _lclose (KERNEL.81)
354 HFILE16 WINAPI _lclose16( HFILE16 hFile )
356 if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile])
358 SetLastError( ERROR_INVALID_HANDLE );
359 return HFILE_ERROR16;
361 TRACE("%d (handle32=%p)\n", hFile, dos_handles[hFile] );
362 CloseHandle( dos_handles[hFile] );
363 dos_handles[hFile] = 0;
364 return 0;
367 /***********************************************************************
368 * _lcreat (KERNEL.83)
370 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
372 return Win32HandleToDosFileHandle( (HANDLE)_lcreat( path, attr ) );
375 /***********************************************************************
376 * _llseek (KERNEL.84)
378 * FIXME:
379 * Seeking before the start of the file should be allowed for _llseek16,
380 * but cause subsequent I/O operations to fail (cf. interrupt list)
383 LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
385 return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin );
389 /***********************************************************************
390 * _lopen (KERNEL.85)
392 HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
394 return Win32HandleToDosFileHandle( (HANDLE)_lopen( path, mode ) );
398 /***********************************************************************
399 * _lread16 (KERNEL.82)
401 UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
403 return (UINT16)_lread((HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
407 /***********************************************************************
408 * _lwrite (KERNEL.86)
410 UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
412 return (UINT16)_hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
415 /***********************************************************************
416 * _hread (KERNEL.349)
418 LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
420 LONG maxlen;
422 TRACE("%d %08x %d\n", hFile, (DWORD)buffer, count );
424 /* Some programs pass a count larger than the allocated buffer */
425 maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
426 if (count > maxlen) count = maxlen;
427 return _lread((HFILE)DosFileHandleToWin32Handle(hFile), MapSL(buffer), count );
431 /***********************************************************************
432 * _lread (KERNEL.82)
434 UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
436 return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
440 /***********************************************************************
441 * _hwrite (KERNEL.350)
443 LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
445 return _hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
449 /***********************************************************************
450 * GetTempDrive (KERNEL.92)
451 * A closer look at krnl386.exe shows what the SDK doesn't mention:
453 * returns:
454 * AL: driveletter
455 * AH: ':' - yes, some kernel code even does stosw with
456 * the returned AX.
457 * DX: 1 for success
459 UINT WINAPI GetTempDrive( BYTE ignored )
461 WCHAR buffer[8];
462 BYTE ret;
464 if (GetTempPathW( 8, buffer )) ret = (BYTE)toupperW(buffer[0]);
465 else ret = 'C';
466 return MAKELONG( ret | (':' << 8), 1 );
470 /***********************************************************************
471 * GetTempFileName (KERNEL.97)
473 UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
474 LPSTR buffer )
476 char temppath[MAX_PATH];
477 char *prefix16 = NULL;
478 UINT16 ret;
480 if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */
482 GetCurrentDirectoryA(sizeof(temppath), temppath);
483 drive |= temppath[0];
486 if (drive & TF_FORCEDRIVE)
488 char d[3];
490 d[0] = drive & ~TF_FORCEDRIVE;
491 d[1] = ':';
492 d[2] = '\0';
493 if (GetDriveTypeA(d) == DRIVE_NO_ROOT_DIR)
495 drive &= ~TF_FORCEDRIVE;
496 WARN("invalid drive %d specified\n", drive );
500 if (drive & TF_FORCEDRIVE)
501 sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE );
502 else
503 GetTempPathA( MAX_PATH, temppath );
505 if (prefix)
507 prefix16 = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + 2);
508 *prefix16 = '~';
509 strcpy(prefix16 + 1, prefix);
512 ret = GetTempFileNameA( temppath, prefix16, unique, buffer );
514 HeapFree(GetProcessHeap(), 0, prefix16);
515 return ret;
519 /***********************************************************************
520 * GetPrivateProfileInt (KERNEL.127)
522 UINT16 WINAPI GetPrivateProfileInt16( LPCSTR section, LPCSTR entry,
523 INT16 def_val, LPCSTR filename )
525 /* we used to have some elaborate return value limitation (<= -32768 etc.)
526 * here, but Win98SE doesn't care about this at all, so I deleted it.
527 * AFAIR versions prior to Win9x had these limits, though. */
528 return (INT16)GetPrivateProfileIntA(section,entry,def_val,filename);
532 /***********************************************************************
533 * GetPrivateProfileString (KERNEL.128)
535 INT16 WINAPI GetPrivateProfileString16( LPCSTR section, LPCSTR entry,
536 LPCSTR def_val, LPSTR buffer,
537 UINT16 len, LPCSTR filename )
539 if (!section)
541 if (buffer && len) buffer[0] = 0;
542 return 0;
544 if (!entry)
546 /* We have to return the list of keys in the section but without the values
547 * so we need to massage the results of GetPrivateProfileSectionA.
549 UINT ret, oldlen = len, size = min( len, 1024 );
550 LPSTR data, src;
552 for (;;)
554 if (!(data = HeapAlloc(GetProcessHeap(), 0, size ))) return 0;
555 ret = GetPrivateProfileSectionA( section, data, size, filename );
556 if (!ret)
558 if (len) *buffer = 0;
559 HeapFree( GetProcessHeap(), 0, data );
560 return 0;
562 if (ret != size - 2) break;
563 /* overflow, try again */
564 size *= 2;
565 HeapFree( GetProcessHeap(), 0, data );
568 src = data;
569 while (len && *src)
571 char *p = strchr( src, '=' );
573 if (!p) p = src + strlen(src);
574 if (p - src < len)
576 memcpy( buffer, src, p - src );
577 buffer += p - src;
578 *buffer++ = 0;
579 len -= (p - src) + 1;
580 src += strlen(src) + 1;
582 else /* overflow */
584 memcpy( buffer, src, len );
585 buffer += len;
586 len = 0;
589 HeapFree( GetProcessHeap(), 0, data );
591 if (len)
593 *buffer = 0;
594 return oldlen - len;
596 if (oldlen > 2)
598 buffer[-2] = 0;
599 buffer[-1] = 0;
600 return oldlen - 2;
602 return 0;
604 return GetPrivateProfileStringA( section, entry, def_val, buffer, len, filename );
608 /***********************************************************************
609 * WritePrivateProfileString (KERNEL.129)
611 BOOL16 WINAPI WritePrivateProfileString16( LPCSTR section, LPCSTR entry,
612 LPCSTR string, LPCSTR filename )
614 return WritePrivateProfileStringA(section,entry,string,filename);
618 /***********************************************************************
619 * GetWindowsDirectory (KERNEL.134)
621 UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count )
623 return GetWindowsDirectoryA( path, count );
627 /***********************************************************************
628 * GetSystemDirectory (KERNEL.135)
630 UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count )
632 static const char * system16 = "\\SYSTEM";
633 char windir[MAX_PATH];
634 UINT16 len;
636 len = GetWindowsDirectory16(windir, sizeof(windir) - sizeof(system16)) + sizeof(system16);
637 if (count >= len)
639 lstrcpyA(path, windir);
640 lstrcatA(path, system16);
641 len--; /* space for the terminating zero is not included on success */
643 return len;
647 /***********************************************************************
648 * GetDriveType (KERNEL.136)
649 * Get the type of a drive in Win16.
651 * RETURNS
652 * The type of the Drive. For a list see GetDriveTypeW from kernel32.
654 * NOTES
655 * Note that it returns DRIVE_REMOTE for CD-ROMs, since MSCDEX uses the
656 * remote drive API. The return value DRIVE_REMOTE for CD-ROMs has been
657 * verified on Win 3.11 and Windows 95. Some programs rely on it, so don't
658 * do any pseudo-clever changes.
660 UINT16 WINAPI GetDriveType16( UINT16 drive ) /* [in] number (NOT letter) of drive */
662 UINT type;
663 WCHAR root[3];
665 root[0] = 'A' + drive;
666 root[1] = ':';
667 root[2] = 0;
668 type = GetDriveTypeW( root );
669 if (type == DRIVE_CDROM) type = DRIVE_REMOTE;
670 else if (type == DRIVE_NO_ROOT_DIR) type = DRIVE_UNKNOWN;
671 return type;
675 /***********************************************************************
676 * GetProfileSectionNames (KERNEL.142)
678 WORD WINAPI GetProfileSectionNames16(LPSTR buffer, WORD size)
681 return GetPrivateProfileSectionNamesA(buffer,size,"win.ini");
685 /***********************************************************************
686 * GetPrivateProfileSectionNames (KERNEL.143)
688 WORD WINAPI GetPrivateProfileSectionNames16( LPSTR buffer, WORD size,
689 LPCSTR filename )
691 return GetPrivateProfileSectionNamesA(buffer,size,filename);
695 /***********************************************************************
696 * CreateDirectory (KERNEL.144)
698 BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy )
700 return CreateDirectoryA( path, NULL );
704 /***********************************************************************
705 * RemoveDirectory (KERNEL.145)
707 BOOL16 WINAPI RemoveDirectory16( LPCSTR path )
709 return RemoveDirectoryA( path );
713 /***********************************************************************
714 * DeleteFile (KERNEL.146)
716 BOOL16 WINAPI DeleteFile16( LPCSTR path )
718 return DeleteFileA( path );
722 /***********************************************************************
723 * SetHandleCount (KERNEL.199)
725 UINT16 WINAPI SetHandleCount16( UINT16 count )
727 return SetHandleCount( count );
731 /***********************************************************************
732 * GetShortPathName (KERNEL.274)
734 WORD WINAPI GetShortPathName16( LPCSTR longpath, LPSTR shortpath, WORD len )
736 return GetShortPathNameA( longpath, shortpath, len );
740 /***********************************************************************
741 * WriteOutProfiles (KERNEL.315)
743 void WINAPI WriteOutProfiles16(void)
745 WritePrivateProfileSectionW( NULL, NULL, NULL );
749 /***********************************************************************
750 * WritePrivateProfileStruct (KERNEL.406)
752 BOOL16 WINAPI WritePrivateProfileStruct16 (LPCSTR section, LPCSTR key,
753 LPVOID buf, UINT16 bufsize, LPCSTR filename)
755 return WritePrivateProfileStructA( section, key, buf, bufsize, filename );
759 /***********************************************************************
760 * GetPrivateProfileStruct (KERNEL.407)
762 BOOL16 WINAPI GetPrivateProfileStruct16(LPCSTR section, LPCSTR key,
763 LPVOID buf, UINT16 len, LPCSTR filename)
765 return GetPrivateProfileStructA( section, key, buf, len, filename );
769 /***********************************************************************
770 * GetCurrentDirectory (KERNEL.411)
772 UINT16 WINAPI GetCurrentDirectory16( UINT16 buflen, LPSTR buf )
774 return GetCurrentDirectoryA( buflen, buf );
778 /***********************************************************************
779 * SetCurrentDirectory (KERNEL.412)
781 BOOL16 WINAPI SetCurrentDirectory16( LPCSTR dir )
783 char fulldir[MAX_PATH];
785 if (!GetFullPathNameA( dir, MAX_PATH, fulldir, NULL )) return FALSE;
787 if (!SetCurrentDirectoryA( dir )) return FALSE;
789 if (fulldir[0] && fulldir[1] == ':')
791 TDB *pTask = GlobalLock16( GetCurrentTask() );
792 char env_var[4] = "=A:";
794 env_var[1] = fulldir[0];
795 SetEnvironmentVariableA( env_var, fulldir );
797 /* update the directory in the TDB */
798 if (pTask)
800 pTask->curdrive = 0x80 | (fulldir[0] - 'A');
801 GetShortPathNameA( fulldir + 2, pTask->curdir, sizeof(pTask->curdir) );
804 return TRUE;
808 /*************************************************************************
809 * FindFirstFile (KERNEL.413)
811 HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATAA *data )
813 HGLOBAL16 h16;
814 HANDLE handle, *ptr;
816 if (!(h16 = GlobalAlloc16( GMEM_MOVEABLE, sizeof(handle) ))) return INVALID_HANDLE_VALUE16;
817 ptr = GlobalLock16( h16 );
818 *ptr = handle = FindFirstFileA( path, data );
819 GlobalUnlock16( h16 );
821 if (handle == INVALID_HANDLE_VALUE)
823 GlobalFree16( h16 );
824 h16 = INVALID_HANDLE_VALUE16;
826 return h16;
830 /*************************************************************************
831 * FindNextFile (KERNEL.414)
833 BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATAA *data )
835 HANDLE *ptr;
836 BOOL ret = FALSE;
838 if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle )))
840 SetLastError( ERROR_INVALID_HANDLE );
841 return ret;
843 ret = FindNextFileA( *ptr, data );
844 GlobalUnlock16( handle );
845 return ret;
849 /*************************************************************************
850 * FindClose (KERNEL.415)
852 BOOL16 WINAPI FindClose16( HANDLE16 handle )
854 HANDLE *ptr;
856 if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle )))
858 SetLastError( ERROR_INVALID_HANDLE );
859 return FALSE;
861 FindClose( *ptr );
862 GlobalUnlock16( handle );
863 GlobalFree16( handle );
864 return TRUE;
868 /***********************************************************************
869 * WritePrivateProfileSection (KERNEL.416)
871 BOOL16 WINAPI WritePrivateProfileSection16( LPCSTR section,
872 LPCSTR string, LPCSTR filename )
874 return WritePrivateProfileSectionA( section, string, filename );
878 /***********************************************************************
879 * WriteProfileSection (KERNEL.417)
881 BOOL16 WINAPI WriteProfileSection16( LPCSTR section, LPCSTR keys_n_values)
883 return WritePrivateProfileSection16( section, keys_n_values, "win.ini");
887 /***********************************************************************
888 * GetPrivateProfileSection (KERNEL.418)
890 INT16 WINAPI GetPrivateProfileSection16( LPCSTR section, LPSTR buffer,
891 UINT16 len, LPCSTR filename )
893 return GetPrivateProfileSectionA( section, buffer, len, filename );
897 /***********************************************************************
898 * GetProfileSection (KERNEL.419)
900 INT16 WINAPI GetProfileSection16( LPCSTR section, LPSTR buffer, UINT16 len )
902 return GetPrivateProfileSection16( section, buffer, len, "win.ini" );
906 /**************************************************************************
907 * GetFileAttributes (KERNEL.420)
909 DWORD WINAPI GetFileAttributes16( LPCSTR name )
911 return GetFileAttributesA( name );
915 /**************************************************************************
916 * SetFileAttributes (KERNEL.421)
918 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
920 return SetFileAttributesA( lpFileName, attributes );
924 /***********************************************************************
925 * GetDiskFreeSpace (KERNEL.422)
927 BOOL16 WINAPI GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors,
928 LPDWORD sector_bytes, LPDWORD free_clusters,
929 LPDWORD total_clusters )
931 return GetDiskFreeSpaceA( root, cluster_sectors, sector_bytes,
932 free_clusters, total_clusters );
935 /***********************************************************************
936 * FileCDR (KERNEL.130)
938 FARPROC16 WINAPI FileCDR16(FARPROC16 x)
940 FIXME("(%p): stub\n", x);
941 return (FARPROC16)TRUE;