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
);
48 /***********************************************************************
49 * _hread16 (KERNEL.349)
51 LONG WINAPI
_hread16( HFILE16 hFile
, LPVOID buffer
, LONG count
)
53 return _lread( (HFILE
)DosFileHandleToWin32Handle(hFile
), buffer
, count
);
57 /***********************************************************************
58 * _hwrite (KERNEL.350)
60 LONG WINAPI
_hwrite16( HFILE16 hFile
, LPCSTR buffer
, LONG count
)
62 return _hwrite( (HFILE
)DosFileHandleToWin32Handle(hFile
), buffer
, count
);
66 /***********************************************************************
69 HFILE16 WINAPI
_lcreat16( LPCSTR path
, INT16 attr
)
71 return Win32HandleToDosFileHandle( (HANDLE
)_lcreat( path
, attr
) );
74 /***********************************************************************
78 * Seeking before the start of the file should be allowed for _llseek16,
79 * but cause subsequent I/O operations to fail (cf. interrupt list)
82 LONG WINAPI
_llseek16( HFILE16 hFile
, LONG lOffset
, INT16 nOrigin
)
84 return SetFilePointer( DosFileHandleToWin32Handle(hFile
), lOffset
, NULL
, nOrigin
);
88 /***********************************************************************
91 HFILE16 WINAPI
_lopen16( LPCSTR path
, INT16 mode
)
93 return Win32HandleToDosFileHandle( (HANDLE
)_lopen( path
, mode
) );
97 /***********************************************************************
98 * _lread16 (KERNEL.82)
100 UINT16 WINAPI
_lread16( HFILE16 hFile
, LPVOID buffer
, UINT16 count
)
102 return (UINT16
)_lread((HFILE
)DosFileHandleToWin32Handle(hFile
), buffer
, (LONG
)count
);
106 /***********************************************************************
107 * _lwrite (KERNEL.86)
109 UINT16 WINAPI
_lwrite16( HFILE16 hFile
, LPCSTR buffer
, UINT16 count
)
111 return (UINT16
)_hwrite( (HFILE
)DosFileHandleToWin32Handle(hFile
), buffer
, (LONG
)count
);
114 /***********************************************************************
115 * _hread (KERNEL.349)
117 LONG WINAPI
WIN16_hread( HFILE16 hFile
, SEGPTR buffer
, LONG count
)
121 TRACE("%d %08lx %ld\n", hFile
, (DWORD
)buffer
, count
);
123 /* Some programs pass a count larger than the allocated buffer */
124 maxlen
= GetSelectorLimit16( SELECTOROF(buffer
) ) - OFFSETOF(buffer
) + 1;
125 if (count
> maxlen
) count
= maxlen
;
126 return _lread((HFILE
)DosFileHandleToWin32Handle(hFile
), MapSL(buffer
), count
);
130 /***********************************************************************
133 UINT16 WINAPI
WIN16_lread( HFILE16 hFile
, SEGPTR buffer
, UINT16 count
)
135 return (UINT16
)WIN16_hread( hFile
, buffer
, (LONG
)count
);
139 /***********************************************************************
140 * DeleteFile (KERNEL.146)
142 BOOL16 WINAPI
DeleteFile16( LPCSTR path
)
144 return DeleteFileA( path
);
147 /**************************************************************************
148 * GetFileAttributes (KERNEL.420)
150 DWORD WINAPI
GetFileAttributes16( LPCSTR name
)
152 return GetFileAttributesA( name
);
156 /***********************************************************************
157 * GetTempFileName (KERNEL.97)
159 UINT16 WINAPI
GetTempFileName16( BYTE drive
, LPCSTR prefix
, UINT16 unique
,
162 char temppath
[MAX_PATH
];
163 char *prefix16
= NULL
;
166 if (!(drive
& ~TF_FORCEDRIVE
)) /* drive 0 means current default drive */
168 GetCurrentDirectoryA(sizeof(temppath
), temppath
);
169 drive
|= temppath
[0];
172 if (drive
& TF_FORCEDRIVE
)
176 d
[0] = drive
& ~TF_FORCEDRIVE
;
179 if (GetDriveTypeA(d
) == DRIVE_NO_ROOT_DIR
)
181 drive
&= ~TF_FORCEDRIVE
;
182 WARN("invalid drive %d specified\n", drive
);
186 if (drive
& TF_FORCEDRIVE
)
187 sprintf(temppath
,"%c:", drive
& ~TF_FORCEDRIVE
);
189 GetTempPathA( MAX_PATH
, temppath
);
193 prefix16
= HeapAlloc(GetProcessHeap(), 0, strlen(prefix
) + 2);
195 strcpy(prefix16
+ 1, prefix
);
198 ret
= GetTempFileNameA( temppath
, prefix16
, unique
, buffer
);
200 if (prefix16
) HeapFree(GetProcessHeap(), 0, prefix16
);
204 /**************************************************************************
205 * SetFileAttributes (KERNEL.421)
207 BOOL16 WINAPI
SetFileAttributes16( LPCSTR lpFileName
, DWORD attributes
)
209 return SetFileAttributesA( lpFileName
, attributes
);
213 /***********************************************************************
214 * SetHandleCount (KERNEL.199)
216 UINT16 WINAPI
SetHandleCount16( UINT16 count
)
218 return SetHandleCount( count
);
222 /*************************************************************************
223 * FindFirstFile (KERNEL.413)
225 HANDLE16 WINAPI
FindFirstFile16( LPCSTR path
, WIN32_FIND_DATAA
*data
)
230 if (!(h16
= GlobalAlloc16( GMEM_MOVEABLE
, sizeof(handle
) ))) return INVALID_HANDLE_VALUE16
;
231 ptr
= GlobalLock16( h16
);
232 *ptr
= handle
= FindFirstFileA( path
, data
);
233 GlobalUnlock16( h16
);
235 if (handle
== INVALID_HANDLE_VALUE
)
238 h16
= INVALID_HANDLE_VALUE16
;
244 /*************************************************************************
245 * FindNextFile (KERNEL.414)
247 BOOL16 WINAPI
FindNextFile16( HANDLE16 handle
, WIN32_FIND_DATAA
*data
)
252 if ((handle
== INVALID_HANDLE_VALUE16
) || !(ptr
= GlobalLock16( handle
)))
254 SetLastError( ERROR_INVALID_HANDLE
);
257 ret
= FindNextFileA( *ptr
, data
);
258 GlobalUnlock16( handle
);
263 /*************************************************************************
264 * FindClose (KERNEL.415)
266 BOOL16 WINAPI
FindClose16( HANDLE16 handle
)
270 if ((handle
== INVALID_HANDLE_VALUE16
) || !(ptr
= GlobalLock16( handle
)))
272 SetLastError( ERROR_INVALID_HANDLE
);
276 GlobalUnlock16( handle
);
277 GlobalFree16( handle
);