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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Fix the CopyFileEx methods to implement the "extended" functionality.
23 * Right now, they simply call the CopyFile method.
27 #include "wine/port.h"
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
40 #include "wine/winbase16.h"
41 #include "wine/server.h"
42 #include "kernel_private.h"
43 #include "wine/unicode.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(file);
49 /***********************************************************************
50 * GetProfileInt (KERNEL.57)
52 UINT16 WINAPI GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val )
54 return GetPrivateProfileInt16( section, entry, def_val, "win.ini" );
58 /***********************************************************************
59 * GetProfileString (KERNEL.58)
61 INT16 WINAPI GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
62 LPSTR buffer, UINT16 len )
64 return GetPrivateProfileString16( section, entry, def_val,
65 buffer, len, "win.ini" );
69 /***********************************************************************
70 * WriteProfileString (KERNEL.59)
72 BOOL16 WINAPI WriteProfileString16( LPCSTR section, LPCSTR entry,
75 return WritePrivateProfileString16( section, entry, string, "win.ini" );
79 /***********************************************************************
82 HFILE16 WINAPI _lclose16( HFILE16 hFile )
84 if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile])
86 SetLastError( ERROR_INVALID_HANDLE );
89 TRACE("%d (handle32=%p)\n", hFile, dos_handles[hFile] );
90 CloseHandle( dos_handles[hFile] );
91 dos_handles[hFile] = 0;
95 /***********************************************************************
98 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
100 return Win32HandleToDosFileHandle( (HANDLE)_lcreat( path, attr ) );
103 /***********************************************************************
104 * _llseek (KERNEL.84)
107 * Seeking before the start of the file should be allowed for _llseek16,
108 * but cause subsequent I/O operations to fail (cf. interrupt list)
111 LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
113 return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin );
117 /***********************************************************************
120 HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
122 return Win32HandleToDosFileHandle( (HANDLE)_lopen( path, mode ) );
126 /***********************************************************************
127 * _lread16 (KERNEL.82)
129 UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
131 return (UINT16)_lread((HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
135 /***********************************************************************
136 * _lwrite (KERNEL.86)
138 UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
140 return (UINT16)_hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
143 /***********************************************************************
144 * _hread (KERNEL.349)
146 LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
150 TRACE("%d %08lx %ld\n", hFile, (DWORD)buffer, count );
152 /* Some programs pass a count larger than the allocated buffer */
153 maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
154 if (count > maxlen) count = maxlen;
155 return _lread((HFILE)DosFileHandleToWin32Handle(hFile), MapSL(buffer), count );
159 /***********************************************************************
162 UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
164 return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
168 /***********************************************************************
169 * GetTempFileName (KERNEL.97)
171 UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
174 char temppath[MAX_PATH];
175 char *prefix16 = NULL;
178 if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */
180 GetCurrentDirectoryA(sizeof(temppath), temppath);
181 drive |= temppath[0];
184 if (drive & TF_FORCEDRIVE)
188 d[0] = drive & ~TF_FORCEDRIVE;
191 if (GetDriveTypeA(d) == DRIVE_NO_ROOT_DIR)
193 drive &= ~TF_FORCEDRIVE;
194 WARN("invalid drive %d specified\n", drive );
198 if (drive & TF_FORCEDRIVE)
199 sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE );
201 GetTempPathA( MAX_PATH, temppath );
205 prefix16 = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + 2);
207 strcpy(prefix16 + 1, prefix);
210 ret = GetTempFileNameA( temppath, prefix16, unique, buffer );
212 if (prefix16) HeapFree(GetProcessHeap(), 0, prefix16);
217 /***********************************************************************
218 * GetPrivateProfileInt (KERNEL.127)
220 UINT16 WINAPI GetPrivateProfileInt16( LPCSTR section, LPCSTR entry,
221 INT16 def_val, LPCSTR filename )
223 /* we used to have some elaborate return value limitation (<= -32768 etc.)
224 * here, but Win98SE doesn't care about this at all, so I deleted it.
225 * AFAIR versions prior to Win9x had these limits, though. */
226 return (INT16)GetPrivateProfileIntA(section,entry,def_val,filename);
230 /***********************************************************************
231 * WritePrivateProfileString (KERNEL.129)
233 BOOL16 WINAPI WritePrivateProfileString16( LPCSTR section, LPCSTR entry,
234 LPCSTR string, LPCSTR filename )
236 return WritePrivateProfileStringA(section,entry,string,filename);
240 /***********************************************************************
241 * GetWindowsDirectory (KERNEL.134)
243 UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count )
245 return GetWindowsDirectoryA( path, count );
249 /***********************************************************************
250 * GetSystemDirectory (KERNEL.135)
252 UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count )
254 return GetSystemDirectoryA( path, count );
258 /***********************************************************************
259 * GetDriveType (KERNEL.136)
260 * This function returns the type of a drive in Win16.
261 * Note that it returns DRIVE_REMOTE for CD-ROMs, since MSCDEX uses the
262 * remote drive API. The return value DRIVE_REMOTE for CD-ROMs has been
263 * verified on Win 3.11 and Windows 95. Some programs rely on it, so don't
264 * do any pseudo-clever changes.
266 UINT16 WINAPI GetDriveType16( UINT16 drive ) /* [in] number (NOT letter) of drive */
271 root[0] = 'A' + drive;
274 type = GetDriveTypeW( root );
275 if (type == DRIVE_CDROM) type = DRIVE_REMOTE;
280 /***********************************************************************
281 * GetProfileSectionNames (KERNEL.142)
283 WORD WINAPI GetProfileSectionNames16(LPSTR buffer, WORD size)
286 return GetPrivateProfileSectionNamesA(buffer,size,"win.ini");
290 /***********************************************************************
291 * GetPrivateProfileSectionNames (KERNEL.143)
293 WORD WINAPI GetPrivateProfileSectionNames16( LPSTR buffer, WORD size,
296 return GetPrivateProfileSectionNamesA(buffer,size,filename);
300 /***********************************************************************
301 * CreateDirectory (KERNEL.144)
303 BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy )
305 return CreateDirectoryA( path, NULL );
309 /***********************************************************************
310 * RemoveDirectory (KERNEL.145)
312 BOOL16 WINAPI RemoveDirectory16( LPCSTR path )
314 return RemoveDirectoryA( path );
318 /***********************************************************************
319 * DeleteFile (KERNEL.146)
321 BOOL16 WINAPI DeleteFile16( LPCSTR path )
323 return DeleteFileA( path );
327 /***********************************************************************
328 * SetHandleCount (KERNEL.199)
330 UINT16 WINAPI SetHandleCount16( UINT16 count )
332 return SetHandleCount( count );
336 /***********************************************************************
337 * _hread16 (KERNEL.349)
339 LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count)
341 return _lread( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
345 /***********************************************************************
346 * _hwrite (KERNEL.350)
348 LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
350 return _hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
354 /***********************************************************************
355 * WritePrivateProfileStruct (KERNEL.406)
357 BOOL16 WINAPI WritePrivateProfileStruct16 (LPCSTR section, LPCSTR key,
358 LPVOID buf, UINT16 bufsize, LPCSTR filename)
360 return WritePrivateProfileStructA( section, key, buf, bufsize, filename );
364 /***********************************************************************
365 * GetPrivateProfileStruct (KERNEL.407)
367 BOOL16 WINAPI GetPrivateProfileStruct16(LPCSTR section, LPCSTR key,
368 LPVOID buf, UINT16 len, LPCSTR filename)
370 return GetPrivateProfileStructA( section, key, buf, len, filename );
374 /***********************************************************************
375 * SetCurrentDirectory (KERNEL.412)
377 BOOL16 WINAPI SetCurrentDirectory16( LPCSTR dir )
379 return SetCurrentDirectoryA( dir );
383 /*************************************************************************
384 * FindFirstFile (KERNEL.413)
386 HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATAA *data )
391 if (!(h16 = GlobalAlloc16( GMEM_MOVEABLE, sizeof(handle) ))) return INVALID_HANDLE_VALUE16;
392 ptr = GlobalLock16( h16 );
393 *ptr = handle = FindFirstFileA( path, data );
394 GlobalUnlock16( h16 );
396 if (handle == INVALID_HANDLE_VALUE)
399 h16 = INVALID_HANDLE_VALUE16;
405 /*************************************************************************
406 * FindNextFile (KERNEL.414)
408 BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATAA *data )
413 if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle )))
415 SetLastError( ERROR_INVALID_HANDLE );
418 ret = FindNextFileA( *ptr, data );
419 GlobalUnlock16( handle );
424 /*************************************************************************
425 * FindClose (KERNEL.415)
427 BOOL16 WINAPI FindClose16( HANDLE16 handle )
431 if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle )))
433 SetLastError( ERROR_INVALID_HANDLE );
437 GlobalUnlock16( handle );
438 GlobalFree16( handle );
443 /***********************************************************************
444 * WritePrivateProfileSection (KERNEL.416)
446 BOOL16 WINAPI WritePrivateProfileSection16( LPCSTR section,
447 LPCSTR string, LPCSTR filename )
449 return WritePrivateProfileSectionA( section, string, filename );
453 /***********************************************************************
454 * WriteProfileSection (KERNEL.417)
456 BOOL16 WINAPI WriteProfileSection16( LPCSTR section, LPCSTR keys_n_values)
458 return WritePrivateProfileSection16( section, keys_n_values, "win.ini");
462 /***********************************************************************
463 * GetPrivateProfileSection (KERNEL.418)
465 INT16 WINAPI GetPrivateProfileSection16( LPCSTR section, LPSTR buffer,
466 UINT16 len, LPCSTR filename )
468 return GetPrivateProfileSectionA( section, buffer, len, filename );
472 /***********************************************************************
473 * GetProfileSection (KERNEL.419)
475 INT16 WINAPI GetProfileSection16( LPCSTR section, LPSTR buffer, UINT16 len )
477 return GetPrivateProfileSection16( section, buffer, len, "win.ini" );
481 /**************************************************************************
482 * GetFileAttributes (KERNEL.420)
484 DWORD WINAPI GetFileAttributes16( LPCSTR name )
486 return GetFileAttributesA( name );
490 /**************************************************************************
491 * SetFileAttributes (KERNEL.421)
493 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
495 return SetFileAttributesA( lpFileName, attributes );
499 /***********************************************************************
500 * GetDiskFreeSpace (KERNEL.422)
502 BOOL16 WINAPI GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors,
503 LPDWORD sector_bytes, LPDWORD free_clusters,
504 LPDWORD total_clusters )
506 return GetDiskFreeSpaceA( root, cluster_sectors, sector_bytes,
507 free_clusters, total_clusters );