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