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