ReactOS 0.4.15-dev-5666-gc548b97
stream.h File Reference

Console I/O streams. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INVALID_CP   ((UINT)-1)
 
#define StdIn   (&csStdIn )
 
#define StdOut   (&csStdOut)
 
#define StdErr   (&csStdErr)
 
#define ConInitStdStreamsAndMode(Mode, CacheCodePage)
 
#define ConInitStdStreams()    ConInitStdStreamsAndMode(AnsiText, INVALID_CP)
 
#define ConStdStreamsSetCacheCodePage(InputCodePage, OutputCodePage)
 

Typedefs

typedef enum _CON_STREAM_MODE CON_STREAM_MODE
 
typedef enum _CON_STREAM_MODEPCON_STREAM_MODE
 
typedef struct _CON_STREAM CON_STREAM
 
typedef struct _CON_STREAMPCON_STREAM
 
typedef INT(__stdcallCON_WRITE_FUNC) (IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)
 

Enumerations

enum  _CON_STREAM_MODE {
  Binary = 0 , AnsiText , WideText , UTF16Text ,
  UTF8Text
}
 

Functions

BOOL ConStreamInitEx (OUT PCON_STREAM Stream, IN PVOID Handle, IN CON_STREAM_MODE Mode, IN UINT CacheCodePage OPTIONAL, IN CON_WRITE_FUNC WriteFunc OPTIONAL)
 
BOOL ConStreamInit (OUT PCON_STREAM Stream, IN PVOID Handle, IN CON_STREAM_MODE Mode, IN UINT CacheCodePage OPTIONAL)
 
BOOL ConStreamSetMode (IN PCON_STREAM Stream, IN CON_STREAM_MODE Mode, IN UINT CacheCodePage OPTIONAL)
 
BOOL ConStreamSetCacheCodePage (IN PCON_STREAM Stream, IN UINT CacheCodePage)
 
HANDLE ConStreamGetOSHandle (IN PCON_STREAM Stream)
 
BOOL ConStreamSetOSHandle (IN PCON_STREAM Stream, IN HANDLE Handle)
 

Variables

CON_STREAM csStdIn
 
CON_STREAM csStdOut
 
CON_STREAM csStdErr
 

Detailed Description

Console I/O streams.

Definition in file stream.h.

Macro Definition Documentation

◆ ConInitStdStreams

#define ConInitStdStreams ( )     ConInitStdStreamsAndMode(AnsiText, INVALID_CP)

Definition at line 128 of file stream.h.

◆ ConInitStdStreamsAndMode

#define ConInitStdStreamsAndMode (   Mode,
  CacheCodePage 
)
Value:
do { \
ConStreamInit(StdIn , GetStdHandle(STD_INPUT_HANDLE) , (Mode), (CacheCodePage)); \
ConStreamInit(StdOut, GetStdHandle(STD_OUTPUT_HANDLE), (Mode), (CacheCodePage)); \
ConStreamInit(StdErr, GetStdHandle(STD_ERROR_HANDLE) , (Mode), (CacheCodePage)); \
} while(0)
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
_In_ ULONG Mode
Definition: hubbusif.h:303
#define StdIn
Definition: stream.h:81
#define StdOut
Definition: stream.h:82
#define StdErr
Definition: stream.h:83
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define STD_ERROR_HANDLE
Definition: winbase.h:269

Definition at line 114 of file stream.h.

◆ ConStdStreamsSetCacheCodePage

#define ConStdStreamsSetCacheCodePage (   InputCodePage,
  OutputCodePage 
)
Value:
do { \
ConStreamSetCacheCodePage(StdIn , (InputCodePage )); \
ConStreamSetCacheCodePage(StdOut, (OutputCodePage)); \
ConStreamSetCacheCodePage(StdErr, (OutputCodePage)); \
} while(0)
UINT InputCodePage
Definition: console.c:25
UINT OutputCodePage
Definition: console.c:26

Definition at line 152 of file stream.h.

◆ INVALID_CP

#define INVALID_CP   ((UINT)-1)

Definition at line 53 of file stream.h.

◆ StdErr

#define StdErr   (&csStdErr)

Definition at line 83 of file stream.h.

◆ StdIn

#define StdIn   (&csStdIn )

Definition at line 81 of file stream.h.

◆ StdOut

#define StdOut   (&csStdOut)

Definition at line 82 of file stream.h.

Typedef Documentation

◆ CON_STREAM

Definition at line 56 of file stream.h.

◆ CON_STREAM_MODE

NOTE: Experimental! Don't use USE_CRT yet because output to console is a bit broken

◆ CON_WRITE_FUNC

typedef INT(__stdcall * CON_WRITE_FUNC) (IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)

Definition at line 63 of file stream.h.

◆ PCON_STREAM

Definition at line 56 of file stream.h.

◆ PCON_STREAM_MODE

Enumeration Type Documentation

◆ _CON_STREAM_MODE

NOTE: Experimental! Don't use USE_CRT yet because output to console is a bit broken

Enumerator
Binary 
AnsiText 
WideText 
UTF16Text 
UTF8Text 

Definition at line 43 of file stream.h.

44{
45 Binary = 0, // #define _O_BINARY 0x8000 // file mode is binary (untranslated)
46 // #define _O_RAW _O_BINARY
47 AnsiText, // #define _O_TEXT 0x4000 // file mode is text (translated) -- "ANSI"
48 WideText, // #define _O_WTEXT 0x10000 // file mode is UTF16 with BOM (translated) -- "Unicode" of Windows
49 UTF16Text, // #define _O_U16TEXT 0x20000 // file mode is UTF16 no BOM (translated) -- "" ""
50 UTF8Text, // #define _O_U8TEXT 0x40000 // file mode is UTF8 no BOM (translated)
@ AnsiText
Definition: stream.h:47
@ UTF16Text
Definition: stream.h:49
@ WideText
Definition: stream.h:48
@ Binary
Definition: stream.h:45
@ UTF8Text
Definition: stream.h:50
enum _CON_STREAM_MODE CON_STREAM_MODE
enum _CON_STREAM_MODE * PCON_STREAM_MODE

Function Documentation

◆ ConStreamGetOSHandle()

HANDLE ConStreamGetOSHandle ( IN PCON_STREAM  Stream)

Definition at line 240 of file stream.c.

242{
243 /* Parameters validation */
244 if (!Stream)
246
247 /*
248 * See https://support.microsoft.com/kb/99173
249 * for more details.
250 */
251
252#ifdef USE_CRT
253 if (!Stream->fStream)
255
256 return (HANDLE)_get_osfhandle(_fileno(Stream->fStream));
257#else
258 return Stream->hHandle;
259#endif
260}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
static IStream Stream
Definition: htmldoc.c:1115
_CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle)

Referenced by _tmain(), BreakHandler(), Cleanup(), cmd_beep(), cmd_start(), CommandColor(), ConClearLine(), ConClearScreen(), ConGetScreenInfo(), Execute(), GetHandle(), Initialize(), InputWait(), and PagePrompt().

◆ ConStreamInit()

BOOL ConStreamInit ( OUT PCON_STREAM  Stream,
IN PVOID  Handle,
IN CON_STREAM_MODE  Mode,
IN UINT CacheCodePage  OPTIONAL 
)

Definition at line 185 of file stream.c.

190{
191 return ConStreamInitEx(Stream, Handle, Mode, CacheCodePage, ConWrite);
192}
ULONG Handle
Definition: gdb_input.c:15
INT __stdcall ConWrite(IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)
Definition: outstream.c:85
BOOL ConStreamInitEx(OUT PCON_STREAM Stream, IN PVOID Handle, IN CON_STREAM_MODE Mode, IN UINT CacheCodePage OPTIONAL, IN CON_WRITE_FUNC WriteFunc OPTIONAL)
Definition: stream.c:127

Referenced by _tmain(), and wmain().

◆ ConStreamInitEx()

BOOL ConStreamInitEx ( OUT PCON_STREAM  Stream,
IN PVOID  Handle,
IN CON_STREAM_MODE  Mode,
IN UINT CacheCodePage  OPTIONAL,
IN CON_WRITE_FUNC WriteFunc  OPTIONAL 
)

Definition at line 127 of file stream.c.

134{
135 /* Parameters validation */
136 if (!Stream || !Handle || (Mode > UTF8Text))
137 return FALSE;
138
139#ifdef USE_CRT
140
141 Stream->fStream = (FILE*)Handle;
142
143#else
144
146 return FALSE;
147
148 /*
149 * As the user calls us by giving us an existing handle to attach on,
150 * it is not our duty to close it if we are called again. The user
151 * is responsible for having opened those handles, and is responsible
152 * for closing them!
153 */
154#if 0
155 /* Attempt to close the handle of the old stream */
156 if (/* Stream->IsInitialized && */ Stream->hHandle &&
157 Stream->hHandle != INVALID_HANDLE_VALUE)
158 {
159 CloseHandle(Stream->hHandle);
160 }
161#endif
162
163 /* Initialize the stream critical section if not already done */
164 if (!Stream->IsInitialized)
165 {
166 InitializeCriticalSection/*AndSpinCount*/(&Stream->Lock /* , 4000 */);
167 Stream->IsInitialized = TRUE;
168 }
169
170 Stream->hHandle = (HANDLE)Handle;
171 Stream->IsConsole = IsConsoleHandle(Stream->hHandle);
172
173#endif /* defined(USE_CRT) */
174
175 /* Set the correct file translation mode */
176 CON_STREAM_SET_MODE(Stream, Mode, CacheCodePage);
177
178 /* Use the default 'ConWrite' helper if nothing is specified */
179 Stream->WriteFunc = (WriteFunc ? WriteFunc : ConWrite);
180
181 return TRUE;
182}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define IsConsoleHandle(h)
Definition: console.h:14
#define CON_STREAM_SET_MODE(Stream, Mode, CacheCodePage)
Definition: stream.c:111
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
PVOID HANDLE
Definition: typedefs.h:73

Referenced by ConStreamInit().

◆ ConStreamSetCacheCodePage()

BOOL ConStreamSetCacheCodePage ( IN PCON_STREAM  Stream,
IN UINT  CacheCodePage 
)

Definition at line 215 of file stream.c.

218{
219#ifdef USE_CRT
220// FIXME!
221#warning The ConStreamSetCacheCodePage function does not make much sense with the CRT!
222#else
224
225 /* Parameters validation */
226 if (!Stream)
227 return FALSE;
228
229 /*
230 * Keep the original stream mode but set the correct file code page
231 * (will be reset only if Mode == AnsiText).
232 */
233 Mode = Stream->Mode;
234 CON_STREAM_SET_MODE(Stream, Mode, CacheCodePage);
235#endif
236 return TRUE;
237}

◆ ConStreamSetMode()

BOOL ConStreamSetMode ( IN PCON_STREAM  Stream,
IN CON_STREAM_MODE  Mode,
IN UINT CacheCodePage  OPTIONAL 
)

Definition at line 195 of file stream.c.

199{
200 /* Parameters validation */
201 if (!Stream || (Mode > UTF8Text))
202 return FALSE;
203
204#ifdef USE_CRT
205 if (!Stream->fStream)
206 return FALSE;
207#endif
208
209 /* Set the correct file translation mode */
210 CON_STREAM_SET_MODE(Stream, Mode, CacheCodePage);
211 return TRUE;
212}

Referenced by Initialize().

◆ ConStreamSetOSHandle()

BOOL ConStreamSetOSHandle ( IN PCON_STREAM  Stream,
IN HANDLE  Handle 
)

Definition at line 263 of file stream.c.

266{
267 /* Parameters validation */
268 if (!Stream)
269 return FALSE;
270
271 /*
272 * See https://support.microsoft.com/kb/99173
273 * for more details.
274 */
275
276#ifdef USE_CRT
277 if (!Stream->fStream)
278 return FALSE;
279
280 int fdOut = _open_osfhandle((intptr_t)Handle, _O_TEXT /* FIXME! */);
281 FILE* fpOut = _fdopen(fdOut, "w");
282 *Stream->fStream = *fpOut;
284
285 return TRUE;
286#else
287 /* Flush the stream and reset its handle */
288 if (Stream->hHandle != INVALID_HANDLE_VALUE)
289 FlushFileBuffers(Stream->hHandle);
290
291 Stream->hHandle = Handle;
292 Stream->IsConsole = IsConsoleHandle(Stream->hHandle);
293
294 // NOTE: Mode reset??
295
296 return TRUE;
297#endif
298}
int intptr_t
Definition: crtdefs.h:304
#define _O_TEXT
Definition: cabinet.h:50
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
_Check_return_ _CRTIMP FILE *__cdecl _fdopen(_In_ int _FileHandle, _In_z_ const char *_Mode)
_CRTIMP int __cdecl _open_osfhandle(_In_ intptr_t _OSFileHandle, _In_ int _Flags)

Referenced by SetHandle(), and wmain().

Variable Documentation

◆ csStdErr

CON_STREAM csStdErr
extern

Definition at line 61 of file stream.c.

◆ csStdIn

CON_STREAM csStdIn
extern

Definition at line 59 of file stream.c.

◆ csStdOut

CON_STREAM csStdOut
extern

Definition at line 60 of file stream.c.