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