1 | /* $Id: lfile.cpp,v 1.7 2000-06-16 00:04:30 phaller 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 arg2)
|
---|
108 | {
|
---|
109 | ULONG ulAccess = 0;
|
---|
110 | ULONG ulShare;
|
---|
111 | HANDLE hFile;
|
---|
112 |
|
---|
113 | dprintf(("KERNEL32: _lopen(%s, %08xh)\n",
|
---|
114 | pszFileName,
|
---|
115 | arg2));
|
---|
116 |
|
---|
117 | if (arg2 & ~(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 | ulAccess |= arg2 & OF_READ ? GENERIC_READ : 0;
|
---|
122 | ulAccess |= arg2 & OF_WRITE ? GENERIC_WRITE : 0;
|
---|
123 | ulAccess |= arg2 & OF_READWRITE ? GENERIC_READ | GENERIC_WRITE : 0;
|
---|
124 |
|
---|
125 | /* Share */
|
---|
126 | ulShare = arg2 & (OF_SHARE_COMPAT | OF_SHARE_DENY_NONE | OF_SHARE_DENY_READ | OF_SHARE_DENY_WRITE | OF_SHARE_EXCLUSIVE);
|
---|
127 | if (ulShare == OF_SHARE_DENY_READ)
|
---|
128 | ulShare = FILE_SHARE_WRITE;
|
---|
129 | else if (ulShare == OF_SHARE_DENY_WRITE)
|
---|
130 | ulShare = FILE_SHARE_READ;
|
---|
131 | else if (ulShare == OF_SHARE_DENY_NONE)
|
---|
132 | ulShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
---|
133 | else if (ulShare == OF_SHARE_EXCLUSIVE)
|
---|
134 | ulShare = 0; //no share
|
---|
135 | else if (ulShare == OF_SHARE_COMPAT)
|
---|
136 | ulShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
---|
137 | else
|
---|
138 | {
|
---|
139 | dprintf(("KERNEL32: _lopen - warning incorrect value for arg2 (or incorrect implementation...)\n"));
|
---|
140 | ulShare = 0;
|
---|
141 | }
|
---|
142 |
|
---|
143 | hFile = CreateFileA(pszFileName, /* filename */
|
---|
144 | ulAccess, /* */
|
---|
145 | ulShare, /* */
|
---|
146 | NULL, /* ignore scurity */
|
---|
147 | OPEN_EXISTING, /* open existing file, fail if new */
|
---|
148 | FILE_ATTRIBUTE_NORMAL, /* normal attribs - no flags */ //m$ sets this to 0
|
---|
149 | NULL); /* no template */
|
---|
150 |
|
---|
151 | dprintf(("KERNEL32: _lopen returns %08xh.\n",
|
---|
152 | hFile));
|
---|
153 |
|
---|
154 | // map correct return code for _lopen
|
---|
155 | if (hFile != INVALID_HANDLE_VALUE)
|
---|
156 | return hFile;
|
---|
157 | else
|
---|
158 | return HFILE_ERROR;
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|
162 | /*****************************************************************************
|
---|
163 | * Name : HFILE WIN32API _lread
|
---|
164 | * Purpose : forward call to ReadFile
|
---|
165 | * Parameters:
|
---|
166 | * Variables :
|
---|
167 | * Result :
|
---|
168 | * Remark : Depend on that ReadFile works properly.
|
---|
169 | * Status : Tested
|
---|
170 | *
|
---|
171 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
172 | *****************************************************************************/
|
---|
173 |
|
---|
174 | UINT WIN32API _lread(HFILE arg1,
|
---|
175 | PVOID arg2,
|
---|
176 | UINT arg3)
|
---|
177 | {
|
---|
178 | ULONG rc;
|
---|
179 |
|
---|
180 | // dprintf(("KERNEL32: _lread(%08xh, %08xh, %08xh)\n",
|
---|
181 | // arg1,
|
---|
182 | // arg2,
|
---|
183 | // arg3));
|
---|
184 |
|
---|
185 | if (!ReadFile(arg1,
|
---|
186 | arg2,
|
---|
187 | arg3,
|
---|
188 | &rc,
|
---|
189 | NULL))
|
---|
190 | rc = -1;
|
---|
191 |
|
---|
192 | // dprintf(("KERNEL32: _lread returns %08xh.",
|
---|
193 | // rc));
|
---|
194 |
|
---|
195 | return rc;
|
---|
196 | }
|
---|
197 |
|
---|
198 |
|
---|
199 | /*****************************************************************************
|
---|
200 | * Name : HFILE WIN32API _llseek
|
---|
201 | * Purpose : forward call to SetFilePointer
|
---|
202 | * Parameters:
|
---|
203 | * Variables :
|
---|
204 | * Result :
|
---|
205 | * Remark : Depends on SetFilePointer working
|
---|
206 | * Status : Tested.
|
---|
207 | *
|
---|
208 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
209 | *****************************************************************************/
|
---|
210 |
|
---|
211 | LONG WIN32API _llseek(HFILE arg1,
|
---|
212 | LONG arg2,
|
---|
213 | int arg3)
|
---|
214 | {
|
---|
215 | ULONG rc;
|
---|
216 |
|
---|
217 | dprintf(("KERNEL32: _llseek(%08xh, %08xh, %08xh)\n",
|
---|
218 | arg1,
|
---|
219 | arg2,
|
---|
220 | arg3));
|
---|
221 | if (!(arg3 == FILE_BEGIN ||
|
---|
222 | arg3 == FILE_CURRENT ||
|
---|
223 | arg3 == FILE_END))
|
---|
224 | {
|
---|
225 | dprintf(("KERNEL32: _llseek - incorrect origin - fails.\n" ));
|
---|
226 | return -1;
|
---|
227 | }
|
---|
228 |
|
---|
229 | rc = SetFilePointer(arg1,
|
---|
230 | arg2,
|
---|
231 | NULL,
|
---|
232 | arg3);
|
---|
233 | //returns -1 on error (-1 == 0xffffffff)
|
---|
234 |
|
---|
235 | dprintf(("KERNEL32: _llseek returns %08xh", rc));
|
---|
236 |
|
---|
237 | return rc;
|
---|
238 | }
|
---|
239 |
|
---|
240 |
|
---|
241 | /*****************************************************************************
|
---|
242 | * Name : HFILE WIN32API _lwrite
|
---|
243 | * Purpose : forward call to WriteFile
|
---|
244 | * Parameters:
|
---|
245 | * Variables :
|
---|
246 | * Result :
|
---|
247 | * Remark : Depends on WriteFile working
|
---|
248 | * Status : Tested
|
---|
249 | *
|
---|
250 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
251 | *****************************************************************************/
|
---|
252 |
|
---|
253 | UINT WIN32API _lwrite(HFILE arg1,
|
---|
254 | LPCSTR arg2,
|
---|
255 | UINT arg3)
|
---|
256 | {
|
---|
257 | ULONG rc;
|
---|
258 |
|
---|
259 | dprintf(("KERNEL32: _lwrite(%08xh, %08xh, %08xh)\n",
|
---|
260 | arg1,
|
---|
261 | arg2,
|
---|
262 | arg3));
|
---|
263 |
|
---|
264 | if (!WriteFile(arg1,
|
---|
265 | (PVOID)arg2,
|
---|
266 | arg3,
|
---|
267 | &rc,
|
---|
268 | NULL))
|
---|
269 | rc = -1;
|
---|
270 |
|
---|
271 | dprintf(("KERNEL32: _lwrite returns %08xh.\n",
|
---|
272 | rc));
|
---|
273 |
|
---|
274 | return rc;
|
---|
275 | }
|
---|
276 |
|
---|