ReactOS  0.4.12-dev-409-g9f418243
stream.h File Reference
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)
 

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, IN PTCHAR, IN DWORD)
 

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
 

Macro Definition Documentation

◆ ConInitStdStreams

#define ConInitStdStreams ( )    ConInitStdStreamsAndMode(AnsiText, INVALID_CP)

Definition at line 122 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)
_In_ ULONG Mode
Definition: hubbusif.h:303
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define STD_ERROR_HANDLE
Definition: winbase.h:266
#define StdErr
Definition: stream.h:77
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
#define StdOut
Definition: stream.h:76
#define StdIn
Definition: stream.h:75

Definition at line 108 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 77 of file stream.h.

◆ StdIn

#define StdIn   (&csStdIn )

Definition at line 75 of file stream.h.

◆ StdOut

#define StdOut   (&csStdOut)

Definition at line 76 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, IN PTCHAR, IN DWORD)

Definition at line 60 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)
enum _CON_STREAM_MODE * PCON_STREAM_MODE
Definition: stream.h:45
enum _CON_STREAM_MODE CON_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)
245  return INVALID_HANDLE_VALUE;
246 
247  /*
248  * See https://support.microsoft.com/kb/99173
249  * for more details.
250  */
251 
252 #ifdef USE_CRT
253  if (!Stream->fStream)
254  return INVALID_HANDLE_VALUE;
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:391
_CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle)
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by BreakHandler(), Cleanup(), cmd_beep(), 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 }
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
_In_ ULONG Mode
Definition: hubbusif.h:303
_In_ HANDLE Handle
Definition: extypes.h:390
INT __stdcall ConWrite(IN PCON_STREAM Stream, IN PTCHAR szStr, IN DWORD len)
Definition: outstream.c:85
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

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 CloseHandle
Definition: compat.h:398
_In_ ULONG Mode
Definition: hubbusif.h:303
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
_In_ HANDLE Handle
Definition: extypes.h:390
PVOID HANDLE
Definition: typedefs.h:71
#define IsConsoleHandle(h)
Definition: console.h:14
INT __stdcall ConWrite(IN PCON_STREAM Stream, IN PTCHAR szStr, IN DWORD len)
Definition: outstream.c:85
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
#define CON_STREAM_SET_MODE(Stream, Mode, CacheCodePage)
Definition: stream.c:111

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  return TRUE;
236 #endif
237 }
#define TRUE
Definition: types.h:120
_In_ ULONG Mode
Definition: hubbusif.h:303
enum _CON_STREAM_MODE CON_STREAM_MODE
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
#define CON_STREAM_SET_MODE(Stream, Mode, CacheCodePage)
Definition: stream.c:111

Referenced by cmd_start(), and Execute().

◆ 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 }
#define TRUE
Definition: types.h:120
_In_ ULONG Mode
Definition: hubbusif.h:303
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
#define CON_STREAM_SET_MODE(Stream, Mode, CacheCodePage)
Definition: stream.c:111

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(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 }
#define TRUE
Definition: types.h:120
_Check_return_ _CRTIMP FILE *__cdecl _fdopen(_In_ int _FileHandle, _In_z_ const char *_Mode)
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_In_ HANDLE Handle
Definition: extypes.h:390
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:175
#define IsConsoleHandle(h)
Definition: console.h:14
#define _O_TEXT
Definition: cabinet.h:50
_CRTIMP int __cdecl _open_osfhandle(_In_ intptr_t _OSFileHandle, _In_ int _Flags)
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by SetHandle(), and wmain().

Variable Documentation

◆ csStdErr

CON_STREAM csStdErr

Definition at line 61 of file stream.c.

◆ csStdIn

CON_STREAM csStdIn

Definition at line 59 of file stream.c.

◆ csStdOut

CON_STREAM csStdOut

Definition at line 60 of file stream.c.