source: trunk/src/kernel32/hmstd.cpp@ 8795

Last change on this file since 8795 was 8795, checked in by sandervl, 23 years ago

logging update

File size: 7.0 KB
Line 
1/* $Id: hmstd.cpp,v 1.10 2002-06-27 12:35:56 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#include "winexebase.h"
32
33#define DBG_LOCALLOG DBG_hmstd
34#include "dbglocal.h"
35
36/*****************************************************************************
37 * Defines *
38 *****************************************************************************/
39
40/*****************************************************************************
41 * Structures *
42 *****************************************************************************/
43
44/*****************************************************************************
45 * Local Prototypes *
46 *****************************************************************************/
47
48
49
50/*****************************************************************************
51 * Name : BOOL HMDeviceStandardClass::ReadFile
52 * Purpose : read data from handle / device
53 * Parameters: PHMHANDLEDATA pHMHandleData,
54 * LPCVOID lpBuffer,
55 * DWORD nNumberOfBytesToRead,
56 * LPDWORD lpNumberOfBytesRead,
57 * LPOVERLAPPED lpOverlapped
58 * Variables :
59 * Result : Boolean
60 * Remark :
61 * Status :
62 *
63 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
64 *****************************************************************************/
65
66BOOL HMDeviceStandardClass::ReadFile(PHMHANDLEDATA pHMHandleData,
67 LPCVOID lpBuffer,
68 DWORD nNumberOfBytesToRead,
69 LPDWORD lpNumberOfBytesRead,
70 LPOVERLAPPED lpOverlapped,
71 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
72{
73 BOOL bRC;
74 DWORD bytesread;
75
76 dprintf2(("KERNEL32: HMDeviceStandardClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED\n",
77 lpHMDeviceName,
78 pHMHandleData,
79 lpBuffer,
80 nNumberOfBytesToRead,
81 lpNumberOfBytesRead,
82 lpOverlapped));
83
84 if(lpCompletionRoutine) {
85 dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
86 }
87
88 if(lpNumberOfBytesRead == NULL) {
89 lpNumberOfBytesRead = &bytesread;
90 }
91 if(pHMHandleData->dwUserData != STD_INPUT_HANDLE) {
92 return FALSE;
93 }
94 return O32_ReadFile(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToRead,
95 lpNumberOfBytesRead, lpOverlapped);
96}
97
98
99/*****************************************************************************
100 * Name : BOOL HMDeviceStandardClass::WriteFile
101 * Purpose : write data to handle / device
102 * Parameters: PHMHANDLEDATA pHMHandleData,
103 * LPCVOID lpBuffer,
104 * DWORD nNumberOfBytesToWrite,
105 * LPDWORD lpNumberOfBytesWritten,
106 * LPOVERLAPPED lpOverlapped
107 * Variables :
108 * Result : Boolean
109 * Remark :
110 * Status :
111 *
112 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
113 *****************************************************************************/
114
115BOOL HMDeviceStandardClass::WriteFile(PHMHANDLEDATA pHMHandleData,
116 LPCVOID lpBuffer,
117 DWORD nNumberOfBytesToWrite,
118 LPDWORD lpNumberOfBytesWritten,
119 LPOVERLAPPED lpOverlapped,
120 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
121{
122 DWORD byteswritten;
123 LPVOID lpLowMemBuffer;
124
125 dprintf(("KERNEL32: HMDeviceStandardClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x)",
126 lpHMDeviceName,
127 pHMHandleData,
128 lpBuffer,
129 nNumberOfBytesToWrite,
130 lpNumberOfBytesWritten,
131 lpOverlapped));
132 if (lpNumberOfBytesWritten == NULL)
133 lpNumberOfBytesWritten = &byteswritten;
134 if (lpCompletionRoutine)
135 {
136 dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
137 }
138
139 if (pHMHandleData->dwUserData == STD_INPUT_HANDLE)
140 return FALSE;
141 lpLowMemBuffer = alloca(nNumberOfBytesToWrite);
142 if (lpLowMemBuffer == NULL)
143 {
144 DebugInt3();
145 return FALSE;
146 }
147 memcpy(lpLowMemBuffer, lpBuffer, nNumberOfBytesToWrite);
148
149 if ( WinExe
150 && !WinExe->isConsoleApp()
151 && O32_GetFileType(pHMHandleData->hHMHandle) == FILE_TYPE_UNKNOWN) /* kso */
152 {
153 //DosWrite returns error 436 when PM apps try to write to std out
154 //kso - Jun 23 2002 2:54am:
155 //Yeah, cause PM programs doesn't have working STD* handles unless you redirect them!
156 //So, we should rather check if valid handle than !console.
157 dprintf(("%s (GUI): %.*s", pHMHandleData->dwUserData == STD_ERROR_HANDLE ? "STDERR" : "STDOUT",
158 nNumberOfBytesToWrite, lpLowMemBuffer));
159 return TRUE;
160 }
161
162 dprintf(("%s: %.*s", pHMHandleData->dwUserData == STD_ERROR_HANDLE ? "STDERR" : "STDOUT",
163 nNumberOfBytesToWrite, lpLowMemBuffer));
164 if (!O32_WriteFile(pHMHandleData->hHMHandle, lpLowMemBuffer, nNumberOfBytesToWrite,
165 lpNumberOfBytesWritten, lpOverlapped))
166 {
167 /* Open32 wasn't made for console apps... */
168 dprintf(("STD*: failed with lasterror=%d\n", GetLastError()));
169 return FALSE;
170 }
171 return TRUE;
172}
173
174
175/*****************************************************************************
176 * Name : DWORD HMDeviceStandardClass::GetFileType
177 * Purpose : determine the handle type
178 * Parameters: PHMHANDLEDATA pHMHandleData
179 * Variables :
180 * Result : API returncode
181 * Remark :
182 * Status :
183 *
184 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
185 *****************************************************************************/
186
187DWORD HMDeviceStandardClass::GetFileType(PHMHANDLEDATA pHMHandleData)
188{
189 dprintf2(("KERNEL32: HMDeviceStandardClass::GetFileType %s(%08x)\n",
190 lpHMDeviceName,
191 pHMHandleData));
192 #if 0
193 return FILE_TYPE_CHAR;
194 #else
195 return O32_GetFileType(pHMHandleData->hHMHandle);
196 #endif
197}
Note: See TracBrowser for help on using the repository browser.