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