1 | /* $Id: hmstd.cpp,v 1.3 2001-04-21 09:10:14 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Handle Manager class for standard in, out & error handles
|
---|
5 | *
|
---|
6 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
7 | * Win32 Unified Handle Manager for OS/2
|
---|
8 | * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
|
---|
9 | */
|
---|
10 |
|
---|
11 |
|
---|
12 | /*****************************************************************************
|
---|
13 | * Remark *
|
---|
14 | *****************************************************************************
|
---|
15 |
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*****************************************************************************
|
---|
20 | * Includes *
|
---|
21 | *****************************************************************************/
|
---|
22 |
|
---|
23 | #include <os2win.h>
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <string.h>
|
---|
26 | #include "unicode.h"
|
---|
27 | #include "misc.h"
|
---|
28 |
|
---|
29 | #include "HandleManager.H"
|
---|
30 | #include "hmstd.h"
|
---|
31 |
|
---|
32 | #define DBG_LOCALLOG DBG_hmstd
|
---|
33 | #include "dbglocal.h"
|
---|
34 |
|
---|
35 | /*****************************************************************************
|
---|
36 | * Defines *
|
---|
37 | *****************************************************************************/
|
---|
38 |
|
---|
39 | /*****************************************************************************
|
---|
40 | * Structures *
|
---|
41 | *****************************************************************************/
|
---|
42 |
|
---|
43 | /*****************************************************************************
|
---|
44 | * Local Prototypes *
|
---|
45 | *****************************************************************************/
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | /*****************************************************************************
|
---|
50 | * Name : BOOL HMDeviceStandardClass::ReadFile
|
---|
51 | * Purpose : read data from handle / device
|
---|
52 | * Parameters: PHMHANDLEDATA pHMHandleData,
|
---|
53 | * LPCVOID lpBuffer,
|
---|
54 | * DWORD nNumberOfBytesToRead,
|
---|
55 | * LPDWORD lpNumberOfBytesRead,
|
---|
56 | * LPOVERLAPPED lpOverlapped
|
---|
57 | * Variables :
|
---|
58 | * Result : Boolean
|
---|
59 | * Remark :
|
---|
60 | * Status :
|
---|
61 | *
|
---|
62 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
63 | *****************************************************************************/
|
---|
64 |
|
---|
65 | BOOL HMDeviceStandardClass::ReadFile(PHMHANDLEDATA pHMHandleData,
|
---|
66 | LPCVOID lpBuffer,
|
---|
67 | DWORD nNumberOfBytesToRead,
|
---|
68 | LPDWORD lpNumberOfBytesRead,
|
---|
69 | LPOVERLAPPED lpOverlapped)
|
---|
70 | {
|
---|
71 | BOOL bRC;
|
---|
72 | DWORD bytesread;
|
---|
73 |
|
---|
74 | dprintf2(("KERNEL32: HMDeviceStandardClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED\n",
|
---|
75 | lpHMDeviceName,
|
---|
76 | pHMHandleData,
|
---|
77 | lpBuffer,
|
---|
78 | nNumberOfBytesToRead,
|
---|
79 | lpNumberOfBytesRead,
|
---|
80 | lpOverlapped));
|
---|
81 |
|
---|
82 |
|
---|
83 | if(lpNumberOfBytesRead == NULL) {
|
---|
84 | lpNumberOfBytesRead = &bytesread;
|
---|
85 | }
|
---|
86 | if(pHMHandleData->dwUserData != STD_INPUT_HANDLE) {
|
---|
87 | return FALSE;
|
---|
88 | }
|
---|
89 | return O32_ReadFile(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToRead,
|
---|
90 | lpNumberOfBytesRead, lpOverlapped);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*****************************************************************************
|
---|
94 | * Name : BOOL ReadFileEx
|
---|
95 | * Purpose : The ReadFileEx function reads data from a file asynchronously.
|
---|
96 | * It is designed solely for asynchronous operation, unlike the
|
---|
97 | * ReadFile function, which is designed for both synchronous and
|
---|
98 | * asynchronous operation. ReadFileEx lets an application perform
|
---|
99 | * other processing during a file read operation.
|
---|
100 | * The ReadFileEx function reports its completion status asynchronously,
|
---|
101 | * calling a specified completion routine when reading is completed
|
---|
102 | * and the calling thread is in an alertable wait state.
|
---|
103 | * Parameters: HANDLE hFile handle of file to read
|
---|
104 | * LPVOID lpBuffer address of buffer
|
---|
105 | * DWORD nNumberOfBytesToRead number of bytes to read
|
---|
106 | * LPOVERLAPPED lpOverlapped address of offset
|
---|
107 | * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
|
---|
108 | * Variables :
|
---|
109 | * Result : TRUE / FALSE
|
---|
110 | * Remark :
|
---|
111 | * Status : UNTESTED STUB
|
---|
112 | *
|
---|
113 | * Author : Patrick Haller [Mon, 1998/06/15 08:00]
|
---|
114 | *****************************************************************************/
|
---|
115 | BOOL HMDeviceStandardClass::ReadFileEx(PHMHANDLEDATA pHMHandleData,
|
---|
116 | LPVOID lpBuffer,
|
---|
117 | DWORD nNumberOfBytesToRead,
|
---|
118 | LPOVERLAPPED lpOverlapped,
|
---|
119 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
---|
120 | {
|
---|
121 | dprintf(("ERROR: ReadFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
|
---|
122 | pHMHandleData->hHMHandle,
|
---|
123 | lpBuffer,
|
---|
124 | nNumberOfBytesToRead,
|
---|
125 | lpOverlapped,
|
---|
126 | lpCompletionRoutine));
|
---|
127 |
|
---|
128 | return FALSE;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | /*****************************************************************************
|
---|
133 | * Name : BOOL HMDeviceStandardClass::WriteFile
|
---|
134 | * Purpose : write data to handle / device
|
---|
135 | * Parameters: PHMHANDLEDATA pHMHandleData,
|
---|
136 | * LPCVOID lpBuffer,
|
---|
137 | * DWORD nNumberOfBytesToWrite,
|
---|
138 | * LPDWORD lpNumberOfBytesWritten,
|
---|
139 | * LPOVERLAPPED lpOverlapped
|
---|
140 | * Variables :
|
---|
141 | * Result : Boolean
|
---|
142 | * Remark :
|
---|
143 | * Status :
|
---|
144 | *
|
---|
145 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
146 | *****************************************************************************/
|
---|
147 |
|
---|
148 | BOOL HMDeviceStandardClass::WriteFile(PHMHANDLEDATA pHMHandleData,
|
---|
149 | LPCVOID lpBuffer,
|
---|
150 | DWORD nNumberOfBytesToWrite,
|
---|
151 | LPDWORD lpNumberOfBytesWritten,
|
---|
152 | LPOVERLAPPED lpOverlapped)
|
---|
153 | {
|
---|
154 | DWORD byteswritten;
|
---|
155 | LPVOID lpLowMemBuffer;
|
---|
156 |
|
---|
157 | dprintf2(("KERNEL32: HMDeviceStandardClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
|
---|
158 | lpHMDeviceName,
|
---|
159 | pHMHandleData,
|
---|
160 | lpBuffer,
|
---|
161 | nNumberOfBytesToWrite,
|
---|
162 | lpNumberOfBytesWritten,
|
---|
163 | lpOverlapped));
|
---|
164 | if(lpNumberOfBytesWritten == NULL) {
|
---|
165 | lpNumberOfBytesWritten = &byteswritten;
|
---|
166 | }
|
---|
167 | if(pHMHandleData->dwUserData == STD_INPUT_HANDLE) {
|
---|
168 | return FALSE;
|
---|
169 | }
|
---|
170 | lpLowMemBuffer = alloca(nNumberOfBytesToWrite);
|
---|
171 | if(lpLowMemBuffer == NULL) {
|
---|
172 | DebugInt3();
|
---|
173 | return FALSE;
|
---|
174 | }
|
---|
175 | memcpy(lpLowMemBuffer, lpBuffer, nNumberOfBytesToWrite);
|
---|
176 | return O32_WriteFile(pHMHandleData->hHMHandle, lpLowMemBuffer, nNumberOfBytesToWrite,
|
---|
177 | lpNumberOfBytesWritten, lpOverlapped);
|
---|
178 | }
|
---|
179 |
|
---|
180 | /*****************************************************************************
|
---|
181 | * Name : BOOL WriteFileEx
|
---|
182 | * Purpose : The WriteFileEx function writes data to a file. It is designed
|
---|
183 | * solely for asynchronous operation, unlike WriteFile, which is
|
---|
184 | * designed for both synchronous and asynchronous operation.
|
---|
185 | * WriteFileEx reports its completion status asynchronously,
|
---|
186 | * calling a specified completion routine when writing is completed
|
---|
187 | * and the calling thread is in an alertable wait state.
|
---|
188 | * Parameters: HANDLE hFile handle of file to write
|
---|
189 | * LPVOID lpBuffer address of buffer
|
---|
190 | * DWORD nNumberOfBytesToRead number of bytes to write
|
---|
191 | * LPOVERLAPPED lpOverlapped address of offset
|
---|
192 | * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
|
---|
193 | * Variables :
|
---|
194 | * Result : TRUE / FALSE
|
---|
195 | * Remark :
|
---|
196 | * Status : UNTESTED STUB
|
---|
197 | *
|
---|
198 | * Author : Patrick Haller [Mon, 1998/06/15 08:00]
|
---|
199 | *****************************************************************************/
|
---|
200 |
|
---|
201 | BOOL HMDeviceStandardClass::WriteFileEx(PHMHANDLEDATA pHMHandleData,
|
---|
202 | LPVOID lpBuffer,
|
---|
203 | DWORD nNumberOfBytesToWrite,
|
---|
204 | LPOVERLAPPED lpOverlapped,
|
---|
205 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
---|
206 | {
|
---|
207 | dprintf(("ERROR: WriteFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
|
---|
208 | pHMHandleData->hHMHandle,
|
---|
209 | lpBuffer,
|
---|
210 | nNumberOfBytesToWrite,
|
---|
211 | lpOverlapped,
|
---|
212 | lpCompletionRoutine));
|
---|
213 | return FALSE;
|
---|
214 | }
|
---|
215 |
|
---|
216 | /*****************************************************************************
|
---|
217 | * Name : DWORD HMDeviceStandardClass::GetFileType
|
---|
218 | * Purpose : determine the handle type
|
---|
219 | * Parameters: PHMHANDLEDATA pHMHandleData
|
---|
220 | * Variables :
|
---|
221 | * Result : API returncode
|
---|
222 | * Remark :
|
---|
223 | * Status :
|
---|
224 | *
|
---|
225 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
226 | *****************************************************************************/
|
---|
227 |
|
---|
228 | DWORD HMDeviceStandardClass::GetFileType(PHMHANDLEDATA pHMHandleData)
|
---|
229 | {
|
---|
230 | dprintf2(("KERNEL32: HMDeviceStandardClass::GetFileType %s(%08x)\n",
|
---|
231 | lpHMDeviceName,
|
---|
232 | pHMHandleData));
|
---|
233 |
|
---|
234 | return FILE_TYPE_CHAR;
|
---|
235 | }
|
---|