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