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
);
65 /***********************************************************************
68 HFILE16 WINAPI
_lclose16( HFILE16 hFile
)
70 if ((hFile
>= DOS_TABLE_SIZE
) || !dos_handles
[hFile
])
72 SetLastError( ERROR_INVALID_HANDLE
);
75 TRACE("%d (handle32=%p)\n", hFile
, dos_handles
[hFile
] );
76 CloseHandle( dos_handles
[hFile
] );
77 dos_handles
[hFile
] = 0;
81 /***********************************************************************
84 HFILE16 WINAPI
_lcreat16( LPCSTR path
, INT16 attr
)
86 return Win32HandleToDosFileHandle( (HANDLE
)_lcreat( path
, attr
) );
89 /***********************************************************************
93 * Seeking before the start of the file should be allowed for _llseek16,
94 * but cause subsequent I/O operations to fail (cf. interrupt list)
97 LONG WINAPI
_llseek16( HFILE16 hFile
, LONG lOffset
, INT16 nOrigin
)
99 return SetFilePointer( DosFileHandleToWin32Handle(hFile
), lOffset
, NULL
, nOrigin
);
103 /***********************************************************************
106 HFILE16 WINAPI
_lopen16( LPCSTR path
, INT16 mode
)
108 return Win32HandleToDosFileHandle( (HANDLE
)_lopen( path
, mode
) );
112 /***********************************************************************
113 * _lread16 (KERNEL.82)
115 UINT16 WINAPI
_lread16( HFILE16 hFile
, LPVOID buffer
, UINT16 count
)
117 return (UINT16
)_lread((HFILE
)DosFileHandleToWin32Handle(hFile
), buffer
, (LONG
)count
);
121 /***********************************************************************
122 * _lwrite (KERNEL.86)
124 UINT16 WINAPI
_lwrite16( HFILE16 hFile
, LPCSTR buffer
, UINT16 count
)
126 return (UINT16
)_hwrite( (HFILE
)DosFileHandleToWin32Handle(hFile
), buffer
, (LONG
)count
);
129 /***********************************************************************
130 * _hread (KERNEL.349)
132 LONG WINAPI
WIN16_hread( HFILE16 hFile
, SEGPTR buffer
, LONG count
)
136 TRACE("%d %08lx %ld\n", hFile
, (DWORD
)buffer
, count
);
138 /* Some programs pass a count larger than the allocated buffer */
139 maxlen
= GetSelectorLimit16( SELECTOROF(buffer
) ) - OFFSETOF(buffer
) + 1;
140 if (count
> maxlen
) count
= maxlen
;
141 return _lread((HFILE
)DosFileHandleToWin32Handle(hFile
), MapSL(buffer
), count
);
145 /***********************************************************************
148 UINT16 WINAPI
WIN16_lread( HFILE16 hFile
, SEGPTR buffer
, UINT16 count
)
150 return (UINT16
)WIN16_hread( hFile
, buffer
, (LONG
)count
);
154 /***********************************************************************
155 * DeleteFile (KERNEL.146)
157 BOOL16 WINAPI
DeleteFile16( LPCSTR path
)
159 return DeleteFileA( path
);
162 /**************************************************************************
163 * GetFileAttributes (KERNEL.420)
165 DWORD WINAPI
GetFileAttributes16( LPCSTR name
)
167 return GetFileAttributesA( name
);
171 /***********************************************************************
172 * GetTempFileName (KERNEL.97)
174 UINT16 WINAPI
GetTempFileName16( BYTE drive
, LPCSTR prefix
, UINT16 unique
,
177 char temppath
[MAX_PATH
];
178 char *prefix16
= NULL
;
181 if (!(drive
& ~TF_FORCEDRIVE
)) /* drive 0 means current default drive */
183 GetCurrentDirectoryA(sizeof(temppath
), temppath
);
184 drive
|= temppath
[0];
187 if (drive
& TF_FORCEDRIVE
)
191 d
[0] = drive
& ~TF_FORCEDRIVE
;
194 if (GetDriveTypeA(d
) == DRIVE_NO_ROOT_DIR
)
196 drive
&= ~TF_FORCEDRIVE
;
197 WARN("invalid drive %d specified\n", drive
);
201 if (drive
& TF_FORCEDRIVE
)
202 sprintf(temppath
,"%c:", drive
& ~TF_FORCEDRIVE
);
204 GetTempPathA( MAX_PATH
, temppath
);
208 prefix16
= HeapAlloc(GetProcessHeap(), 0, strlen(prefix
) + 2);
210 strcpy(prefix16
+ 1, prefix
);
213 ret
= GetTempFileNameA( temppath
, prefix16
, unique
, buffer
);
215 if (prefix16
) HeapFree(GetProcessHeap(), 0, prefix16
);
219 /**************************************************************************
220 * SetFileAttributes (KERNEL.421)
222 BOOL16 WINAPI
SetFileAttributes16( LPCSTR lpFileName
, DWORD attributes
)
224 return SetFileAttributesA( lpFileName
, attributes
);
228 /***********************************************************************
229 * SetHandleCount (KERNEL.199)
231 UINT16 WINAPI
SetHandleCount16( UINT16 count
)
233 return SetHandleCount( count
);
237 /*************************************************************************
238 * FindFirstFile (KERNEL.413)
240 HANDLE16 WINAPI
FindFirstFile16( LPCSTR path
, WIN32_FIND_DATAA
*data
)
245 if (!(h16
= GlobalAlloc16( GMEM_MOVEABLE
, sizeof(handle
) ))) return INVALID_HANDLE_VALUE16
;
246 ptr
= GlobalLock16( h16
);
247 *ptr
= handle
= FindFirstFileA( path
, data
);
248 GlobalUnlock16( h16
);
250 if (handle
== INVALID_HANDLE_VALUE
)
253 h16
= INVALID_HANDLE_VALUE16
;
259 /*************************************************************************
260 * FindNextFile (KERNEL.414)
262 BOOL16 WINAPI
FindNextFile16( HANDLE16 handle
, WIN32_FIND_DATAA
*data
)
267 if ((handle
== INVALID_HANDLE_VALUE16
) || !(ptr
= GlobalLock16( handle
)))
269 SetLastError( ERROR_INVALID_HANDLE
);
272 ret
= FindNextFileA( *ptr
, data
);
273 GlobalUnlock16( handle
);
278 /*************************************************************************
279 * FindClose (KERNEL.415)
281 BOOL16 WINAPI
FindClose16( HANDLE16 handle
)
285 if ((handle
== INVALID_HANDLE_VALUE16
) || !(ptr
= GlobalLock16( handle
)))
287 SetLastError( ERROR_INVALID_HANDLE
);
291 GlobalUnlock16( handle
);
292 GlobalFree16( handle
);