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"
44 #include "kernel_private.h"
46 #include "wine/unicode.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(file);
51 /***********************************************************************
52 * _hread16 (KERNEL.349)
54 LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count)
56 return _lread( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
60 /***********************************************************************
61 * _hwrite (KERNEL.350)
63 LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
65 return _hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
69 /***********************************************************************
72 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
74 return Win32HandleToDosFileHandle( (HANDLE)_lcreat( path, attr ) );
77 /***********************************************************************
81 * Seeking before the start of the file should be allowed for _llseek16,
82 * but cause subsequent I/O operations to fail (cf. interrupt list)
85 LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
87 return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin );
91 /***********************************************************************
94 HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
96 return Win32HandleToDosFileHandle( (HANDLE)_lopen( path, mode ) );
100 /***********************************************************************
101 * _lread16 (KERNEL.82)
103 UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
105 return (UINT16)_lread((HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
109 /***********************************************************************
110 * _lwrite (KERNEL.86)
112 UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
114 return (UINT16)_hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
117 /***********************************************************************
118 * _hread (KERNEL.349)
120 LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
124 TRACE("%d %08lx %ld\n", hFile, (DWORD)buffer, count );
126 /* Some programs pass a count larger than the allocated buffer */
127 maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
128 if (count > maxlen) count = maxlen;
129 return _lread((HFILE)DosFileHandleToWin32Handle(hFile), MapSL(buffer), count );
133 /***********************************************************************
136 UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
138 return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
142 /***********************************************************************
143 * DeleteFile (KERNEL.146)
145 BOOL16 WINAPI DeleteFile16( LPCSTR path )
147 return DeleteFileA( path );
150 /**************************************************************************
151 * GetFileAttributes (KERNEL.420)
153 DWORD WINAPI GetFileAttributes16( LPCSTR name )
155 return GetFileAttributesA( name );
159 /***********************************************************************
160 * GetTempFileName (KERNEL.97)
162 UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
165 char temppath[MAX_PATH];
166 char *prefix16 = NULL;
169 if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */
171 GetCurrentDirectoryA(sizeof(temppath), temppath);
172 drive |= temppath[0];
175 if (drive & TF_FORCEDRIVE)
179 d[0] = drive & ~TF_FORCEDRIVE;
182 if (GetDriveTypeA(d) == DRIVE_NO_ROOT_DIR)
184 drive &= ~TF_FORCEDRIVE;
185 WARN("invalid drive %d specified\n", drive );
189 if (drive & TF_FORCEDRIVE)
190 sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE );
192 GetTempPathA( MAX_PATH, temppath );
196 prefix16 = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + 2);
198 strcpy(prefix16 + 1, prefix);
201 ret = GetTempFileNameA( temppath, prefix16, unique, buffer );
203 if (prefix16) HeapFree(GetProcessHeap(), 0, prefix16);
207 /**************************************************************************
208 * SetFileAttributes (KERNEL.421)
210 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
212 return SetFileAttributesA( lpFileName, attributes );
216 /***********************************************************************
217 * SetHandleCount (KERNEL.199)
219 UINT16 WINAPI SetHandleCount16( UINT16 count )
221 return SetHandleCount( count );
225 /*************************************************************************
226 * FindFirstFile (KERNEL.413)
228 HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATAA *data )
233 if (!(h16 = GlobalAlloc16( GMEM_MOVEABLE, sizeof(handle) ))) return INVALID_HANDLE_VALUE16;
234 ptr = GlobalLock16( h16 );
235 *ptr = handle = FindFirstFileA( path, data );
236 GlobalUnlock16( h16 );
238 if (handle == INVALID_HANDLE_VALUE)
241 h16 = INVALID_HANDLE_VALUE16;
247 /*************************************************************************
248 * FindNextFile (KERNEL.414)
250 BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATAA *data )
255 if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle )))
257 SetLastError( ERROR_INVALID_HANDLE );
260 ret = FindNextFileA( *ptr, data );
261 GlobalUnlock16( handle );
266 /*************************************************************************
267 * FindClose (KERNEL.415)
269 BOOL16 WINAPI FindClose16( HANDLE16 handle )
273 if ((handle == INVALID_HANDLE_VALUE16) || !(ptr = GlobalLock16( handle )))
275 SetLastError( ERROR_INVALID_HANDLE );
279 GlobalUnlock16( handle );
280 GlobalFree16( handle );