1 | /* $Id: lfile.cpp,v 1.8 2003-05-12 15:29:09 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | *
|
---|
5 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
6 | *
|
---|
7 | */
|
---|
8 | /*
|
---|
9 | * Win32 compatibility file functions for OS/2
|
---|
10 | *
|
---|
11 | * 1998/06/12 PH Patrick Haller (haller@zebra.fh-weingarten.de)
|
---|
12 | *
|
---|
13 | * @(#) LFILE.C 1.0.0 1998/06/12 PH added HandleManager support
|
---|
14 | * 1.1.0 1998/08/29 KSO corrected error codes and forwarded
|
---|
15 | * to Win32 file api as NT/95 does.
|
---|
16 | * 1.1.1 1999/06/09 PH NOTE: only forard to KERNEL32:FILEIO
|
---|
17 | * calls, never do anything else !
|
---|
18 | */
|
---|
19 |
|
---|
20 |
|
---|
21 | /*****************************************************************************
|
---|
22 | * Includes *
|
---|
23 | *****************************************************************************/
|
---|
24 |
|
---|
25 | #include <os2win.h>
|
---|
26 |
|
---|
27 | #define DBG_LOCALLOG DBG_lfile
|
---|
28 | #include "dbglocal.h"
|
---|
29 |
|
---|
30 |
|
---|
31 | /*****************************************************************************
|
---|
32 | * Name : HFILE WIN32API _lclose
|
---|
33 | * Purpose : forward call to CloseHandle
|
---|
34 | * Parameters:
|
---|
35 | * Variables :
|
---|
36 | * Result :
|
---|
37 | * Remark : Depends on CloseHandle working.
|
---|
38 | * Status : Tested
|
---|
39 | *
|
---|
40 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
41 | *****************************************************************************/
|
---|
42 |
|
---|
43 | HFILE WIN32API _lclose(HFILE arg1)
|
---|
44 | {
|
---|
45 | dprintf(("KERNEL32: _lclose(%08xh)\n",
|
---|
46 | arg1));
|
---|
47 |
|
---|
48 | if (CloseHandle(arg1))
|
---|
49 | return 0;
|
---|
50 | else
|
---|
51 | return -1;
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | /*****************************************************************************
|
---|
56 | * Name : HFILE WIN32API _lcreat
|
---|
57 | * Purpose : forward call to CreateFileA
|
---|
58 | * Parameters:
|
---|
59 | * Variables :
|
---|
60 | * Result :
|
---|
61 | * Remark : Depends on CreateFile working.
|
---|
62 | * Status : Tested
|
---|
63 | *
|
---|
64 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
65 | *****************************************************************************/
|
---|
66 |
|
---|
67 | HFILE WIN32API _lcreat(LPCSTR arg1,
|
---|
68 | int arg2)
|
---|
69 | {
|
---|
70 | HANDLE hFile;
|
---|
71 |
|
---|
72 | dprintf(("KERNEL32: _lcreat(%s, %08xh)\n",
|
---|
73 | arg1,
|
---|
74 | arg2));
|
---|
75 |
|
---|
76 | //if (arg2 & ~(1 | 2 | 4))
|
---|
77 | // dprintf(("KERNEL32: Warning: _lcreat has unknown flag(s) set - fails.\n"));
|
---|
78 |
|
---|
79 | //SetLastError(0); - CreateFileA sets error
|
---|
80 | hFile = CreateFileA(arg1, /* filename */
|
---|
81 | GENERIC_READ | GENERIC_WRITE, /* readwrite access */
|
---|
82 | FILE_SHARE_READ | FILE_SHARE_WRITE,/* share all */
|
---|
83 | NULL, /* ignore scurity */
|
---|
84 | CREATE_ALWAYS, /* create (trunkate don't work) */
|
---|
85 | arg2 & 0x3fb7, /* so M$ does (that is more attributes than I could find in the headers and in the docs!) */
|
---|
86 | NULL); /* no template */
|
---|
87 |
|
---|
88 | dprintf(("KERNEL32: _lcreat returns %08xh.\n",
|
---|
89 | hFile));
|
---|
90 | return hFile;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | /*****************************************************************************
|
---|
95 | * Name : HFILE WIN32API _lopen
|
---|
96 | * Purpose : forward call to CreateFileA
|
---|
97 | * Parameters:
|
---|
98 | * Variables :
|
---|
99 | * Result :
|
---|
100 | * Remark :
|
---|
101 | * Status : Tested
|
---|
102 | *
|
---|
103 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
104 | *****************************************************************************/
|
---|
105 |
|
---|
106 | HFILE WIN32API _lopen(LPCSTR pszFileName,
|
---|
107 | int mode)
|
---|
108 | {
|
---|
109 | ULONG ulAccess = 0;
|
---|
110 | ULONG ulShare;
|
---|
111 | HANDLE hFile;
|
---|
112 |
|
---|
113 | dprintf(("KERNEL32: _lopen(%s, %08xh)\n",
|
---|
114 | pszFileName,
|
---|
115 | mode));
|
---|
116 |
|
---|
117 | if (mode & ~(OF_READ|OF_READWRITE|OF_WRITE|OF_SHARE_COMPAT|OF_SHARE_DENY_NONE|OF_SHARE_DENY_READ|OF_SHARE_DENY_WRITE|OF_SHARE_EXCLUSIVE))
|
---|
118 | dprintf(("KERNEL32: (warn) _lopen has unknown flag(s) set.\n"));
|
---|
119 |
|
---|
120 | /* Access */
|
---|
121 | switch(mode & 0x03)
|
---|
122 | {
|
---|
123 | case OF_READ: ulAccess = GENERIC_READ; break;
|
---|
124 | case OF_WRITE: ulAccess = GENERIC_WRITE; break;
|
---|
125 | case OF_READWRITE: ulAccess = GENERIC_READ | GENERIC_WRITE; break;
|
---|
126 | default: ulAccess = 0; break;
|
---|
127 | }
|
---|
128 |
|
---|
129 | /* Share */
|
---|
130 | ulShare = mode & (OF_SHARE_COMPAT | OF_SHARE_DENY_NONE | OF_SHARE_DENY_READ | OF_SHARE_DENY_WRITE | OF_SHARE_EXCLUSIVE);
|
---|
131 | if (ulShare == OF_SHARE_DENY_READ)
|
---|
132 | ulShare = FILE_SHARE_WRITE;
|
---|
133 | else if (ulShare == OF_SHARE_DENY_WRITE)
|
---|
134 | ulShare = FILE_SHARE_READ;
|
---|
135 | else if (ulShare == OF_SHARE_DENY_NONE)
|
---|
136 | ulShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
---|
137 | else if (ulShare == OF_SHARE_EXCLUSIVE)
|
---|
138 | ulShare = 0; //no share
|
---|
139 | else if (ulShare == OF_SHARE_COMPAT)
|
---|
140 | ulShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
---|
141 | else
|
---|
142 | {
|
---|
143 | dprintf(("KERNEL32: _lopen - warning incorrect value for arg2 (or incorrect implementation...)\n"));
|
---|
144 | ulShare = 0;
|
---|
145 | }
|
---|
146 |
|
---|
147 | hFile = CreateFileA(pszFileName, /* filename */
|
---|
148 | ulAccess, /* */
|
---|
149 | ulShare, /* */
|
---|
150 | NULL, /* ignore scurity */
|
---|
151 | OPEN_EXISTING, /* open existing file, fail if new */
|
---|
152 | FILE_ATTRIBUTE_NORMAL, /* normal attribs - no flags */ //m$ sets this to 0
|
---|
153 | NULL); /* no template */
|
---|
154 |
|
---|
155 | dprintf(("KERNEL32: _lopen returns %08xh.\n",
|
---|
156 | hFile));
|
---|
157 |
|
---|
158 | // map correct return code for _lopen
|
---|
159 | if (hFile != INVALID_HANDLE_VALUE)
|
---|
160 | return hFile;
|
---|
161 | else
|
---|
162 | return HFILE_ERROR;
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | /*****************************************************************************
|
---|
167 | * Name : HFILE WIN32API _lread
|
---|
168 | * Purpose : forward call to ReadFile
|
---|
169 | * Parameters:
|
---|
170 | * Variables :
|
---|
171 | * Result :
|
---|
172 | * Remark : Depend on that ReadFile works properly.
|
---|
173 | * Status : Tested
|
---|
174 | *
|
---|
175 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
176 | *****************************************************************************/
|
---|
177 |
|
---|
178 | UINT WIN32API _lread(HFILE arg1,
|
---|
179 | PVOID arg2,
|
---|
180 | UINT arg3)
|
---|
181 | {
|
---|
182 | ULONG rc;
|
---|
183 |
|
---|
184 | // dprintf(("KERNEL32: _lread(%08xh, %08xh, %08xh)\n",
|
---|
185 | // arg1,
|
---|
186 | // arg2,
|
---|
187 | // arg3));
|
---|
188 |
|
---|
189 | if (!ReadFile(arg1,
|
---|
190 | arg2,
|
---|
191 | arg3,
|
---|
192 | &rc,
|
---|
193 | NULL))
|
---|
194 | rc = -1;
|
---|
195 |
|
---|
196 | // dprintf(("KERNEL32: _lread returns %08xh.",
|
---|
197 | // rc));
|
---|
198 |
|
---|
199 | return rc;
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | /*****************************************************************************
|
---|
204 | * Name : HFILE WIN32API _llseek
|
---|
205 | * Purpose : forward call to SetFilePointer
|
---|
206 | * Parameters:
|
---|
207 | * Variables :
|
---|
208 | * Result :
|
---|
209 | * Remark : Depends on SetFilePointer working
|
---|
210 | * Status : Tested.
|
---|
211 | *
|
---|
212 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
213 | *****************************************************************************/
|
---|
214 |
|
---|
215 | LONG WIN32API _llseek(HFILE arg1,
|
---|
216 | LONG arg2,
|
---|
217 | int arg3)
|
---|
218 | {
|
---|
219 | ULONG rc;
|
---|
220 |
|
---|
221 | dprintf(("KERNEL32: _llseek(%08xh, %08xh, %08xh)\n",
|
---|
222 | arg1,
|
---|
223 | arg2,
|
---|
224 | arg3));
|
---|
225 | if (!(arg3 == FILE_BEGIN ||
|
---|
226 | arg3 == FILE_CURRENT ||
|
---|
227 | arg3 == FILE_END))
|
---|
228 | {
|
---|
229 | dprintf(("KERNEL32: _llseek - incorrect origin - fails.\n" ));
|
---|
230 | return -1;
|
---|
231 | }
|
---|
232 |
|
---|
233 | rc = SetFilePointer(arg1,
|
---|
234 | arg2,
|
---|
235 | NULL,
|
---|
236 | arg3);
|
---|
237 | //returns -1 on error (-1 == 0xffffffff)
|
---|
238 |
|
---|
239 | dprintf(("KERNEL32: _llseek returns %08xh", rc));
|
---|
240 |
|
---|
241 | return rc;
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | /*****************************************************************************
|
---|
246 | * Name : HFILE WIN32API _lwrite
|
---|
247 | * Purpose : forward call to WriteFile
|
---|
248 | * Parameters:
|
---|
249 | * Variables :
|
---|
250 | * Result :
|
---|
251 | * Remark : Depends on WriteFile working
|
---|
252 | * Status : Tested
|
---|
253 | *
|
---|
254 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
255 | *****************************************************************************/
|
---|
256 |
|
---|
257 | UINT WIN32API _lwrite(HFILE hFile,
|
---|
258 | LPCSTR lpBuffer,
|
---|
259 | UINT cbWrite)
|
---|
260 | {
|
---|
261 | ULONG rc;
|
---|
262 | dprintf(("KERNEL32: _lwrite(%08xh, %08xh, %08xh)\n", hFile, lpBuffer, cbWrite));
|
---|
263 |
|
---|
264 | if (!cbWrite)
|
---|
265 | rc = SetEndOfFile(hFile) ? 0 : HFILE_ERROR;
|
---|
266 | else
|
---|
267 | {
|
---|
268 | if (!WriteFile(hFile,
|
---|
269 | (PVOID)lpBuffer,
|
---|
270 | cbWrite,
|
---|
271 | &rc,
|
---|
272 | NULL))
|
---|
273 | rc = HFILE_ERROR;
|
---|
274 | }
|
---|
275 |
|
---|
276 | dprintf(("KERNEL32: _lwrite returns %08xh.\n", rc));
|
---|
277 | return rc;
|
---|
278 | }
|
---|
279 |
|
---|