Fixed header dependencies to be fully compatible with the Windows
[wine/multimedia.git] / dlls / kernel / file16.c
blob103fd65730bf1258432c4bbcceb9f26b48349546
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "winreg.h"
39 #include "winternl.h"
40 #include "wine/winbase16.h"
41 #include "wine/server.h"
43 #include "msdos.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 /***********************************************************************
70 * _lcreat (KERNEL.83)
72 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
74 return Win32HandleToDosFileHandle( (HANDLE)_lcreat( path, attr ) );
77 /***********************************************************************
78 * _llseek (KERNEL.84)
80 * FIXME:
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 /***********************************************************************
92 * _lopen (KERNEL.85)
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 )
122 LONG maxlen;
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 /***********************************************************************
134 * _lread (KERNEL.82)
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,
163 LPSTR buffer )
165 char temppath[MAX_PATH];
166 char *prefix16 = NULL;
167 UINT16 ret;
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)
177 char d[3];
179 d[0] = drive & ~TF_FORCEDRIVE;
180 d[1] = ':';
181 d[2] = '\0';
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 );
191 else
192 GetTempPathA( MAX_PATH, temppath );
194 if (prefix)
196 prefix16 = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + 2);
197 *prefix16 = '~';
198 strcpy(prefix16 + 1, prefix);
201 ret = GetTempFileNameA( temppath, prefix16, unique, buffer );
203 if (prefix16) HeapFree(GetProcessHeap(), 0, prefix16);
204 return ret;
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 );