Add an empty hook function for WSASetBlockingHook to return.
[wine] / dlls / kernel / file16.c
1 /*
2  * File handling functions
3  *
4  * Copyright 1993 John Burton
5  * Copyright 1996 Alexandre Julliard
6  *
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.
11  *
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.
16  *
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
20  *
21  * TODO:
22  *    Fix the CopyFileEx methods to implement the "extended" functionality.
23  *    Right now, they simply call the CopyFile method.
24  */
25
26 #include "config.h"
27 #include "wine/port.h"
28
29 #include <stdio.h>
30 #include <assert.h>
31
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
34 #include "winerror.h"
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winternl.h"
38 #include "wine/winbase16.h"
39 #include "wine/server.h"
40
41 #include "msdos.h"
42 #include "kernel_private.h"
43
44 #include "wine/unicode.h"
45 #include "wine/debug.h"
46
47 WINE_DEFAULT_DEBUG_CHANNEL(file);
48
49 /***********************************************************************
50  *           _hread16   (KERNEL.349)
51  */
52 LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count)
53 {
54     return _lread( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
55 }
56
57
58 /***********************************************************************
59  *           _hwrite   (KERNEL.350)
60  */
61 LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
62 {
63     return _hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, count );
64 }
65
66
67 /***********************************************************************
68  *           _lcreat   (KERNEL.83)
69  */
70 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
71 {
72     return Win32HandleToDosFileHandle( (HANDLE)_lcreat( path, attr ) );
73 }
74
75 /***********************************************************************
76  *           _llseek   (KERNEL.84)
77  *
78  * FIXME:
79  *   Seeking before the start of the file should be allowed for _llseek16,
80  *   but cause subsequent I/O operations to fail (cf. interrupt list)
81  *
82  */
83 LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
84 {
85     return SetFilePointer( DosFileHandleToWin32Handle(hFile), lOffset, NULL, nOrigin );
86 }
87
88
89 /***********************************************************************
90  *           _lopen   (KERNEL.85)
91  */
92 HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
93 {
94     return Win32HandleToDosFileHandle( (HANDLE)_lopen( path, mode ) );
95 }
96
97
98 /***********************************************************************
99  *           _lread16   (KERNEL.82)
100  */
101 UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
102 {
103     return (UINT16)_lread((HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
104 }
105
106
107 /***********************************************************************
108  *           _lwrite   (KERNEL.86)
109  */
110 UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
111 {
112     return (UINT16)_hwrite( (HFILE)DosFileHandleToWin32Handle(hFile), buffer, (LONG)count );
113 }
114
115 /***********************************************************************
116  *           _hread (KERNEL.349)
117  */
118 LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
119 {
120     LONG maxlen;
121
122     TRACE("%d %08lx %ld\n", hFile, (DWORD)buffer, count );
123
124     /* Some programs pass a count larger than the allocated buffer */
125     maxlen = GetSelectorLimit16( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
126     if (count > maxlen) count = maxlen;
127     return _lread((HFILE)DosFileHandleToWin32Handle(hFile), MapSL(buffer), count );
128 }
129
130
131 /***********************************************************************
132  *           _lread (KERNEL.82)
133  */
134 UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
135 {
136     return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
137 }
138
139
140 /***********************************************************************
141  *           DeleteFile   (KERNEL.146)
142  */
143 BOOL16 WINAPI DeleteFile16( LPCSTR path )
144 {
145     return DeleteFileA( path );
146 }
147
148 /**************************************************************************
149  *           GetFileAttributes   (KERNEL.420)
150  */
151 DWORD WINAPI GetFileAttributes16( LPCSTR name )
152 {
153     return GetFileAttributesA( name );
154 }
155
156
157 /***********************************************************************
158  *           GetTempFileName   (KERNEL.97)
159  */
160 UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
161                                  LPSTR buffer )
162 {
163     char temppath[MAX_PATH];
164     char *prefix16 = NULL;
165     UINT16 ret;
166
167     if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */
168     {
169         GetCurrentDirectoryA(sizeof(temppath), temppath); 
170         drive |= temppath[0];
171     }
172
173     if (drive & TF_FORCEDRIVE)
174     {
175         char    d[3];
176
177         d[0] = drive & ~TF_FORCEDRIVE;
178         d[1] = ':';
179         d[2] = '\0';
180         if (GetDriveTypeA(d) == DRIVE_NO_ROOT_DIR)
181         {
182             drive &= ~TF_FORCEDRIVE;
183             WARN("invalid drive %d specified\n", drive );
184         }
185     }
186
187     if (drive & TF_FORCEDRIVE)
188         sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE );
189     else
190         GetTempPathA( MAX_PATH, temppath );
191
192     if (prefix)
193     {
194         prefix16 = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + 2);
195         *prefix16 = '~';
196         strcpy(prefix16 + 1, prefix);
197     }
198
199     ret = GetTempFileNameA( temppath, prefix16, unique, buffer );
200
201     if (prefix16) HeapFree(GetProcessHeap(), 0, prefix16);
202     return ret;
203 }
204
205 /**************************************************************************
206  *              SetFileAttributes       (KERNEL.421)
207  */
208 BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
209 {
210     return SetFileAttributesA( lpFileName, attributes );
211 }
212
213
214 /***********************************************************************
215  *           SetHandleCount   (KERNEL.199)
216  */
217 UINT16 WINAPI SetHandleCount16( UINT16 count )
218 {
219     return SetHandleCount( count );
220 }