ReactOS  0.4.14-dev-55-g2da92ac
outstream.c File Reference

Console I/O utility API – Output. More...

#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <winuser.h>
#include <wincon.h>
#include <strsafe.h>
#include <pseh/pseh2.h>
#include "conutils.h"
#include "stream.h"
#include "stream_private.h"
Include dependency graph for outstream.c:

Go to the source code of this file.

Macros

#define UNICODE
 
#define _UNICODE
 
#define CON_RC_STRING_MAX_SIZE   4096
 

Functions

ConStreamWrite

Writes a counted string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the counted string to write.
[in]lenLength of the string pointed by szStr, specified in number of characters.
Returns
Numbers of characters successfully written to Stream.
INT ConStreamWrite (IN PCON_STREAM Stream, IN PTCHAR szStr, IN DWORD len)
 
ConPuts

Writes a NULL-terminated string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the NULL-terminated string to write.
Returns
Numbers of characters successfully written to Stream.
Remarks
Contrary to the CRT puts() function, ConPuts() does not append a terminating new-line character. In this way it behaves more like the CRT fputs() function.
INT ConPuts (IN PCON_STREAM Stream, IN LPWSTR szStr)
 
ConPrintfV

Formats and writes a NULL-terminated string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the NULL-terminated format string, that follows the same specifications as the szStr format string in ConPrintf().
[in]argsParameter describing a variable number of arguments, initialized with va_start(), that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), printf(), vprintf()
INT ConPrintfV (IN PCON_STREAM Stream, IN LPWSTR szStr, IN va_list args)
 
ConPrintf

Formats and writes a NULL-terminated string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the NULL-terminated format string, that follows the same specifications as the format string in printf(). This string can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested.
[in]...Additional arguments that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintfV(), printf(), vprintf()
INT __cdecl ConPrintf (IN PCON_STREAM Stream, IN LPWSTR szStr,...)
 
ConResPutsEx

Writes a string resource to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]uIDThe identifier of the string to be written.
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
Returns
Numbers of characters successfully written to Stream.
Remarks
Similarly to ConPuts(), no terminating new-line character is appended.
See also
ConPuts(), ConResPuts()
INT ConResPutsEx (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId)
 
ConResPuts

Writes a string resource contained in the current application to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]uIDThe identifier of the string to be written.
Returns
Numbers of characters successfully written to Stream.
Remarks
Similarly to ConPuts(), no terminating new-line character is appended.
See also
ConPuts(), ConResPutsEx()
INT ConResPuts (IN PCON_STREAM Stream, IN UINT uID)
 
ConResPrintfExV

Formats and writes a string resource to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]uIDThe identifier of the format string. The format string follows the same specifications as the szStr format string in ConPrintf().
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
[in]argsParameter describing a variable number of arguments, initialized with va_start(), that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintfEx(), ConResPrintfV(), ConResPrintf()
INT ConResPrintfExV (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, IN va_list args)
 
ConResPrintfV

Formats and writes a string resource contained in the current application to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]uIDThe identifier of the format string. The format string follows the same specifications as the szStr format string in ConPrintf().
[in]argsParameter describing a variable number of arguments, initialized with va_start(), that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintfExV(), ConResPrintfEx(), ConResPrintf()
INT ConResPrintfV (IN PCON_STREAM Stream, IN UINT uID, IN va_list args)
 
ConResPrintfEx

Formats and writes a string resource to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]uIDThe identifier of the format string. The format string follows the same specifications as the szStr format string in ConPrintf().
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
[in]...Additional arguments that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintfExV(), ConResPrintfV(), ConResPrintf()
INT __cdecl ConResPrintfEx (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId,...)
 
ConResPrintf

Formats and writes a string resource contained in the current application to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]uIDThe identifier of the format string. The format string follows the same specifications as the szStr format string in ConPrintf().
[in]...Additional arguments that can be expected by the function, depending on the szStr format string. Each argument is used to replace a format specifier in the format string.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintfExV(), ConResPrintfEx(), ConResPrintfV()
INT __cdecl ConResPrintf (IN PCON_STREAM Stream, IN UINT uID,...)
 
ConMsgPuts

Writes a message string to a stream without formatting. The function requires a message definition as input. The message definition can come from a buffer passed to the function. It can come from a message table resource in an already-loaded module, or the caller can ask the function to search the system's message table resource(s) for the message definition. Please refer to the Win32 FormatMessage() function for more details.

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, and how to interpret the lpSource parameter. See FormatMessage() for more details. The FORMAT_MESSAGE_ALLOCATE_BUFFER and FORMAT_MESSAGE_ARGUMENT_ARRAY flags are always ignored. The function implicitly uses the FORMAT_MESSAGE_IGNORE_INSERTS flag to implement its behaviour.
[in]lpSourceThe location of the message definition. The type of this parameter depends upon the settings in the dwFlags parameter.
[in]dwMessageIdThe message identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]dwLanguageIdThe language identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
Returns
Numbers of characters successfully written to Stream.
Remarks
Similarly to ConPuts(), no terminating new-line character is appended.
See also
ConPuts(), ConResPuts() and associated functions, FormatMessage() (on MSDN)
INT ConMsgPuts (IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
 
ConMsgPrintf2V

Formats and writes a message string to a stream.

Remarks
For internal use only.
See also
ConMsgPrintfV()
INT ConMsgPrintf2V (IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list args)
 
ConMsgPrintfV

Formats and writes a message string to a stream. The function requires a message definition as input. The message definition can come from a buffer passed to the function. It can come from a message table resource in an already-loaded module, or the caller can ask the function to search the system's message table resource(s) for the message definition. Please refer to the Win32 FormatMessage() function for more details.

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, and how to interpret the lpSource parameter. See FormatMessage() for more details. The FORMAT_MESSAGE_ALLOCATE_BUFFER flag is always ignored.
[in]lpSourceThe location of the message definition. The type of this parameter depends upon the settings in the dwFlags parameter.
[in]dwMessageIdThe message identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]dwLanguageIdThe language identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]ArgumentsOptional pointer to an array of values describing a variable number of arguments, depending on the message string. Each argument is used to replace an insert sequence in the message string. By default, the Arguments parameter is of type va_list*, initialized with va_start(). The state of the va_list argument is undefined upon return from the function. To use the va_list again, destroy the variable argument list pointer using va_end() and reinitialize it with va_start(). If you do not have a pointer of type va_list*, then specify the FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array of DWORD_PTR values; those values are input to the message formatted as the insert values. Each insert must have a corresponding element in the array.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT ConMsgPrintfV (IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list *Arguments OPTIONAL)
 
ConMsgPrintf

Formats and writes a message string to a stream. The function requires a message definition as input. The message definition can come from a buffer passed to the function. It can come from a message table resource in an already-loaded module, or the caller can ask the function to search the system's message table resource(s) for the message definition. Please refer to the Win32 FormatMessage() function for more details.

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, and how to interpret the lpSource parameter. See FormatMessage() for more details. The FORMAT_MESSAGE_ALLOCATE_BUFFER and FORMAT_MESSAGE_ARGUMENT_ARRAY flags are always ignored.
[in]lpSourceThe location of the message definition. The type of this parameter depends upon the settings in the dwFlags parameter.
[in]dwMessageIdThe message identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]dwLanguageIdThe language identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
[in]...Additional arguments that can be expected by the function, depending on the message string. Each argument is used to replace an insert sequence in the message string.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintfV(), FormatMessage() (on MSDN)
INT __cdecl ConMsgPrintf (IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId,...)
 
ConResMsgPrintfExV

Formats and writes a message string to a stream. The function requires a message definition as input. Contrary to the ConMsg* or the Win32 FormatMessage() functions, the message definition comes from a resource string table, much like the strings for ConResPrintf(), but is formatted according to the rules of ConMsgPrintf().

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]dwFlagsThe formatting options, see FormatMessage() for more details. The only valid flags are FORMAT_MESSAGE_ARGUMENT_ARRAY, FORMAT_MESSAGE_IGNORE_INSERTS and FORMAT_MESSAGE_MAX_WIDTH_MASK. All the other flags are internally overridden by the function to implement its behaviour.
[in]uIDThe identifier of the message string. The format string follows the same specifications as the lpSource format string in ConMsgPrintf().
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
[in]ArgumentsOptional pointer to an array of values describing a variable number of arguments, depending on the message string. Each argument is used to replace an insert sequence in the message string. By default, the Arguments parameter is of type va_list*, initialized with va_start(). The state of the va_list argument is undefined upon return from the function. To use the va_list again, destroy the variable argument list pointer using va_end() and reinitialize it with va_start(). If you do not have a pointer of type va_list*, then specify the FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array of DWORD_PTR values; those values are input to the message formatted as the insert values. Each insert must have a corresponding element in the array.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT ConResMsgPrintfExV (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN DWORD dwFlags, IN UINT uID, IN LANGID LanguageId, IN va_list *Arguments OPTIONAL)
 
ConResMsgPrintfV

Formats and writes a message string to a stream. The function requires a message definition as input. Contrary to the ConMsg* or the Win32 FormatMessage() functions, the message definition comes from a resource string table, much like the strings for ConResPrintf(), but is formatted according to the rules of ConMsgPrintf().

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, see FormatMessage() for more details. The only valid flags are FORMAT_MESSAGE_ARGUMENT_ARRAY, FORMAT_MESSAGE_IGNORE_INSERTS and FORMAT_MESSAGE_MAX_WIDTH_MASK. All the other flags are internally overridden by the function to implement its behaviour.
[in]uIDThe identifier of the message string. The format string follows the same specifications as the lpSource format string in ConMsgPrintf().
[in]ArgumentsOptional pointer to an array of values describing a variable number of arguments, depending on the message string. Each argument is used to replace an insert sequence in the message string. By default, the Arguments parameter is of type va_list*, initialized with va_start(). The state of the va_list argument is undefined upon return from the function. To use the va_list again, destroy the variable argument list pointer using va_end() and reinitialize it with va_start(). If you do not have a pointer of type va_list*, then specify the FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array of DWORD_PTR values; those values are input to the message formatted as the insert values. Each insert must have a corresponding element in the array.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT ConResMsgPrintfV (IN PCON_STREAM Stream, IN DWORD dwFlags, IN UINT uID, IN va_list *Arguments OPTIONAL)
 
ConResMsgPrintfEx

Formats and writes a message string to a stream. The function requires a message definition as input. Contrary to the ConMsg* or the Win32 FormatMessage() functions, the message definition comes from a resource string table, much like the strings for ConResPrintf(), but is formatted according to the rules of ConMsgPrintf().

Parameters
[in]StreamStream to which the write operation is issued.
[in]hInstanceOptional handle to an instance of the module whose executable file contains the string resource. Can be set to NULL to get the handle to the application itself.
[in]dwFlagsThe formatting options, see FormatMessage() for more details. The only valid flags are FORMAT_MESSAGE_IGNORE_INSERTS and FORMAT_MESSAGE_MAX_WIDTH_MASK. All the other flags are internally overridden by the function to implement its behaviour.
[in]uIDThe identifier of the message string. The format string follows the same specifications as the lpSource format string in ConMsgPrintf().
[in]LanguageIdThe language identifier of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. To specify a language other than the current language, use the MAKELANGID macro to create this parameter.
[in]...Additional arguments that can be expected by the function, depending on the message string. Each argument is used to replace an insert sequence in the message string.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT __cdecl ConResMsgPrintfEx (IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN DWORD dwFlags, IN UINT uID, IN LANGID LanguageId,...)
 
ConResMsgPrintf

Formats and writes a message string to a stream. The function requires a message definition as input. Contrary to the ConMsg* or the Win32 FormatMessage() functions, the message definition comes from a resource string table, much like the strings for ConResPrintf(), but is formatted according to the rules of ConMsgPrintf().

Parameters
[in]StreamStream to which the write operation is issued.
[in]dwFlagsThe formatting options, see FormatMessage() for more details. The only valid flags are FORMAT_MESSAGE_IGNORE_INSERTS and FORMAT_MESSAGE_MAX_WIDTH_MASK. All the other flags are internally overridden by the function to implement its behaviour.
[in]uIDThe identifier of the message string. The format string follows the same specifications as the lpSource format string in ConMsgPrintf().
[in]...Additional arguments that can be expected by the function, depending on the message string. Each argument is used to replace an insert sequence in the message string.
Remarks
Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, the ConMsg* functions work on format strings that contain insert sequences. These sequences extend the standard format specifiers as they allow to specify an insert number referring which precise value given in arguments to use.
Returns
Numbers of characters successfully written to Stream.
See also
ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), FormatMessage() (on MSDN)
INT __cdecl ConResMsgPrintf (IN PCON_STREAM Stream, IN DWORD dwFlags, IN UINT uID,...)
 
VOID ConClearLine (IN PCON_STREAM Stream)
 

ConWrite

Writes a counted string to a stream.

Parameters
[in]StreamStream to which the write operation is issued.
[in]szStrPointer to the counted string to write.
[in]lenLength of the string pointed by szStr, specified in number of characters.
Returns
Numbers of characters successfully written to Stream.
Note
This function is used as an internal function. Use the ConStreamWrite() function instead.
Remarks
Should be called with the stream locked.
#define CON_STREAM_WRITE_CALL(Stream, Str, Len)   (Stream)->WriteFunc((Stream), (Str), (Len))
 
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
 
#define CON_STREAM_WRITE(Stream, Str, Len)
 
INT __stdcall ConWrite (IN PCON_STREAM Stream, IN PTCHAR szStr, IN DWORD len)
 

Detailed Description

Console I/O utility API – Output.

Definition in file outstream.c.

Macro Definition Documentation

◆ _UNICODE

#define _UNICODE

Definition at line 28 of file outstream.c.

◆ CON_RC_STRING_MAX_SIZE

#define CON_RC_STRING_MAX_SIZE   4096

Definition at line 56 of file outstream.c.

◆ CON_STREAM_WRITE

#define CON_STREAM_WRITE (   Stream,
  Str,
  Len 
)
Value:
do { \
EnterCriticalSection(&(Stream)->Lock); \
CON_STREAM_WRITE_CALL((Stream), (Str), (Len)); \
LeaveCriticalSection(&(Stream)->Lock); \
} while(0)
#define Len
Definition: deflate.h:82
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Definition at line 360 of file outstream.c.

◆ CON_STREAM_WRITE2

#define CON_STREAM_WRITE2 (   Stream,
  Str,
  Len,
  RetLen 
)
Value:
do { \
EnterCriticalSection(&(Stream)->Lock); \
(RetLen) = CON_STREAM_WRITE_CALL((Stream), (Str), (Len)); \
LeaveCriticalSection(&(Stream)->Lock); \
} while(0)
#define Len
Definition: deflate.h:82
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
#define CON_STREAM_WRITE_CALL(Stream, Str, Len)
Definition: outstream.c:347

Definition at line 353 of file outstream.c.

◆ CON_STREAM_WRITE_CALL

#define CON_STREAM_WRITE_CALL (   Stream,
  Str,
  Len 
)    (Stream)->WriteFunc((Stream), (Str), (Len))

Definition at line 347 of file outstream.c.

◆ UNICODE

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

Definition at line 27 of file outstream.c.

Function Documentation

◆ ConClearLine()

VOID ConClearLine ( IN PCON_STREAM  Stream)

Definition at line 1483 of file outstream.c.

1484 {
1485  HANDLE hOutput = ConStreamGetOSHandle(Stream);
1486 
1487  /*
1488  * Erase the full line where the cursor is, and move
1489  * the cursor back to the beginning of the line.
1490  */
1491 
1492  if (IsConsoleHandle(hOutput))
1493  {
1495  DWORD dwWritten;
1496 
1497  GetConsoleScreenBufferInfo(hOutput, &csbi);
1498 
1499  csbi.dwCursorPosition.X = 0;
1500  // csbi.dwCursorPosition.Y;
1501 
1502  FillConsoleOutputCharacterW(hOutput, L' ',
1503  csbi.dwSize.X,
1504  csbi.dwCursorPosition,
1505  &dwWritten);
1507  }
1508  else if (IsTTYHandle(hOutput))
1509  {
1510  ConPuts(Stream, L"\x1B[2K\x1B[1G"); // FIXME: Just use WriteFile
1511  }
1512  // else, do nothing for files
1513 }
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:590
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
ULONG X
Definition: bl.h:1340
BOOL IsTTYHandle(IN HANDLE hHandle)
Definition: utils.c:342
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IsConsoleHandle(h)
Definition: console.h:14
static const WCHAR L[]
Definition: oid.c:1250
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput, IN WCHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
Definition: readwrite.c:1676

Referenced by PagePrompt().

◆ ConMsgPrintf()

INT __cdecl ConMsgPrintf ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN LPCVOID lpSource  OPTIONAL,
IN DWORD  dwMessageId,
IN DWORD  dwLanguageId,
  ... 
)

Definition at line 1130 of file outstream.c.

1137 {
1138  INT Len;
1139  va_list args;
1140 
1141  /* Sanitize dwFlags */
1143 
1144  va_start(args, dwLanguageId);
1146  dwFlags,
1147  lpSource,
1148  dwMessageId,
1149  dwLanguageId,
1150  &args);
1151  va_end(args);
1152 
1153  return Len;
1154 }
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
INT ConMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1030
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
#define Len
Definition: deflate.h:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

◆ ConMsgPrintf2V()

INT ConMsgPrintf2V ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN LPCVOID lpSource  OPTIONAL,
IN DWORD  dwMessageId,
IN DWORD  dwLanguageId,
IN va_list  args 
)

Definition at line 909 of file outstream.c.

916 {
917  INT Len;
918  DWORD dwLength = 0;
919  LPWSTR lpMsgBuf = NULL;
920 
921  /*
922  * Sanitize dwFlags. This version always ignore explicitely the inserts.
923  * The string that we will return to the user will not be pre-formatted.
924  */
925  dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
926  dwFlags |= FORMAT_MESSAGE_IGNORE_INSERTS; // Ignore inserts for FormatMessage.
928 
929  /*
930  * Retrieve the message string without appending extra newlines.
931  * Wrap in SEH to protect from invalid string parameters.
932  */
933  _SEH2_TRY
934  {
936  lpSource,
937  dwMessageId,
938  dwLanguageId,
939  (LPWSTR)&lpMsgBuf,
940  0,
941  NULL);
942  }
944  {
945  }
946  _SEH2_END;
947 
948  Len = (INT)dwLength;
949 
950  if (!lpMsgBuf)
951  {
952  // ASSERT(dwLength == 0);
953  }
954  else
955  {
956  // ASSERT(dwLength != 0);
957 
958  /* lpMsgBuf is NULL-terminated by FormatMessage */
959  Len = ConPrintfV(Stream, lpMsgBuf, args);
960  // CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len);
961 
962  /* Fixup returned length in case of errors */
963  if (Len < 0)
964  Len = 0;
965 
966  /* Free the buffer allocated by FormatMessage */
967  LocalFree(lpMsgBuf);
968  }
969 
970  return Len;
971 }
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
#define INT
Definition: polytest.cpp:20
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
_SEH2_TRY
Definition: create.c:4250
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
static DWORD DWORD * dwLength
Definition: fusion.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
_SEH2_END
Definition: create.c:4424
INT ConPrintfV(IN PCON_STREAM Stream, IN LPWSTR szStr, IN va_list args)
Definition: outstream.c:466
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
WCHAR * LPWSTR
Definition: xmlstorage.h:184
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

◆ ConMsgPrintfV()

INT ConMsgPrintfV ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN LPCVOID lpSource  OPTIONAL,
IN DWORD  dwMessageId,
IN DWORD  dwLanguageId,
IN va_list *Arguments  OPTIONAL 
)

Definition at line 1030 of file outstream.c.

1037 {
1038  INT Len;
1039  DWORD dwLength = 0;
1040  LPWSTR lpMsgBuf = NULL;
1041 
1042  /* Sanitize dwFlags */
1043  dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
1044 
1045  /*
1046  * Retrieve the message string without appending extra newlines.
1047  * Use the "safe" FormatMessage version (SEH-protected) to protect
1048  * from invalid string parameters.
1049  */
1051  lpSource,
1052  dwMessageId,
1053  dwLanguageId,
1054  (LPWSTR)&lpMsgBuf,
1055  0,
1056  Arguments);
1057 
1058  Len = (INT)dwLength;
1059 
1060  if (!lpMsgBuf)
1061  {
1062  // ASSERT(dwLength == 0);
1063  }
1064  else
1065  {
1066  // ASSERT(dwLength != 0);
1067 
1068  CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len);
1069 
1070  /* Fixup returned length in case of errors */
1071  if (Len < 0)
1072  Len = 0;
1073 
1074  /* Free the buffer allocated by FormatMessage */
1075  LocalFree(lpMsgBuf);
1076  }
1077 
1078  return Len;
1079 }
#define INT
Definition: polytest.cpp:20
int32_t INT
Definition: typedefs.h:56
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
Definition: outstream.c:353
static DWORD DWORD * dwLength
Definition: fusion.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
WCHAR * LPWSTR
Definition: xmlstorage.h:184
DWORD WINAPI FormatMessageSafeW(IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, OUT LPWSTR lpBuffer, IN DWORD nSize, IN va_list *Arguments OPTIONAL)
Definition: utils.c:254
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by ConFormatMessage(), and ConMsgPrintf().

◆ ConMsgPuts()

INT ConMsgPuts ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN LPCVOID lpSource  OPTIONAL,
IN DWORD  dwMessageId,
IN DWORD  dwLanguageId 
)

Definition at line 837 of file outstream.c.

843 {
844  INT Len;
845  DWORD dwLength = 0;
846  LPWSTR lpMsgBuf = NULL;
847 
848  /*
849  * Sanitize dwFlags. This version always ignore explicitely the inserts
850  * as we emulate the behaviour of the (f)puts function.
851  */
852  dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
853  dwFlags |= FORMAT_MESSAGE_IGNORE_INSERTS; // Ignore inserts for FormatMessage.
855 
856  /*
857  * Retrieve the message string without appending extra newlines.
858  * Wrap in SEH to protect from invalid string parameters.
859  */
860  _SEH2_TRY
861  {
863  lpSource,
864  dwMessageId,
865  dwLanguageId,
866  (LPWSTR)&lpMsgBuf,
867  0,
868  NULL);
869  }
871  {
872  }
873  _SEH2_END;
874 
875  Len = (INT)dwLength;
876 
877  if (!lpMsgBuf)
878  {
879  // ASSERT(dwLength == 0);
880  }
881  else
882  {
883  // ASSERT(dwLength != 0);
884 
885  /* lpMsgBuf is NULL-terminated by FormatMessage */
886  // Len = ConPuts(Stream, lpMsgBuf);
887  CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len);
888 
889  /* Fixup returned length in case of errors */
890  if (Len < 0)
891  Len = 0;
892 
893  /* Free the buffer allocated by FormatMessage */
894  LocalFree(lpMsgBuf);
895  }
896 
897  return Len;
898 }
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
#define INT
Definition: polytest.cpp:20
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
int32_t INT
Definition: typedefs.h:56
_SEH2_TRY
Definition: create.c:4250
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
Definition: outstream.c:353
static DWORD DWORD * dwLength
Definition: fusion.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
_SEH2_END
Definition: create.c:4424
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
WCHAR * LPWSTR
Definition: xmlstorage.h:184
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by DisplayError(), DoFormatMessage(), PrintError(), and PrintWin32Error().

◆ ConPrintf()

INT __cdecl ConPrintf ( IN PCON_STREAM  Stream,
IN LPWSTR  szStr,
  ... 
)

Definition at line 520 of file outstream.c.

524 {
525  INT Len;
526  va_list args;
527 
528  // Len = vfwprintf(Stream->fStream, szMsgBuf, args); // vfprintf for direct ANSI
529 
530  // StringCchPrintfW
531  va_start(args, szStr);
532  Len = ConPrintfV(Stream, szStr, args);
533  va_end(args);
534 
535  return Len;
536 }
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
#define Len
Definition: deflate.h:82
INT ConPrintfV(IN PCON_STREAM Stream, IN LPWSTR szStr, IN va_list args)
Definition: outstream.c:466
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by CheckLogOrSourceExistence(), ChkdskCallback(), cmdAccounts(), cmdContinue(), cmdGroup(), cmdHelpMsg(), cmdLocalGroup(), cmdPause(), cmdShare(), cmdStop(), cmdUser(), DisplayError(), DisplayGroup(), DisplayLocalGroup(), DisplayServerConfig(), DisplayServerStatistics(), DisplayShare(), DisplayUser(), DisplayWorkstationConfig(), DisplayWorkstationStatistics(), download_file(), DrawTree(), DumpSubstedDrives(), EnumerateConnections(), EnumerateDevices(), EnumerateGroups(), EnumerateLocalGroups(), EnumerateRunningServices(), EnumerateShares(), EnumerateUsers(), ErrorMessage(), FindString(), FormatExCallback(), PrintAllJobs(), PrintAttribute(), PrintDateTime(), PrintError(), PrintErrorMessage(), PrintFileDacl(), PrintHorizontalLine(), PrintLocalTime(), PrintLogonHours(), PrintParserError(), PrintWin32Error(), SetParallelState(), ShowParallelStatus(), ShowTcpTable(), ShowUdpTable(), StartOneService(), Usage(), wmain(), and write_status().

◆ ConPrintfV()

INT ConPrintfV ( IN PCON_STREAM  Stream,
IN LPWSTR  szStr,
IN va_list  args 
)

Definition at line 466 of file outstream.c.

470 {
471  INT Len;
473 
474  // Len = vfwprintf(Stream->fStream, szStr, args); // vfprintf for direct ANSI
475 
476  /*
477  * Reuse szStr as the pointer to end-of-string, to compute
478  * the string length instead of calling wcslen().
479  */
480  // StringCchVPrintfW(bufSrc, ARRAYSIZE(bufSrc), szStr, args);
481  // Len = wcslen(bufSrc);
482  StringCchVPrintfExW(bufSrc, ARRAYSIZE(bufSrc), &szStr, NULL, 0, szStr, args);
483  Len = szStr - bufSrc;
484 
485  CON_STREAM_WRITE2(Stream, bufSrc, Len, Len);
486 
487  /* Fixup returned length in case of errors */
488  if (Len < 0)
489  Len = 0;
490 
491  return Len;
492 }
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
Definition: outstream.c:353
#define CON_RC_STRING_MAX_SIZE
Definition: outstream.c:56
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define Len
Definition: deflate.h:82
STRSAFEAPI StringCchVPrintfExW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCWSTR pszFormat, va_list argList)
Definition: strsafe.h:661
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by ConMsgPrintf2V(), ConPrintf(), ConResPrintfExV(), and DirPrintf().

◆ ConPuts()

INT ConPuts ( IN PCON_STREAM  Stream,
IN LPWSTR  szStr 
)

Definition at line 427 of file outstream.c.

430 {
431  INT Len;
432 
433  Len = wcslen(szStr);
434  CON_STREAM_WRITE2(Stream, szStr, Len, Len);
435 
436  /* Fixup returned length in case of errors */
437  if (Len < 0)
438  Len = 0;
439 
440  return Len;
441 }
int32_t INT
Definition: typedefs.h:56
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
Definition: outstream.c:353
#define Len
Definition: deflate.h:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by active_main(), automount_main(), break_main(), CBindStatusCallback_OnProgress(), ChkdskCallback(), cmdAccounts(), cmdComputer(), cmdConfig(), cmdContinue(), cmdGroup(), cmdHelp(), cmdHelpMsg(), cmdLocalGroup(), cmdPause(), cmdShare(), cmdStart(), cmdStatistics(), cmdStop(), cmdSyntax(), cmdUser(), ConClearLine(), ConClearScreen(), CtrlCIntercept(), DisplayGroup(), DisplayLocalGroup(), DisplayServerConfig(), DisplayTableHeader(), DisplayUser(), DisplayWorkstationConfig(), EnumerateDevices(), EnumerateGroups(), EnumerateLocalGroups(), EnumerateRunningServices(), EnumerateShares(), EnumerateUsers(), help_cmdlist(), InputWait(), ListDisk(), ListPartition(), ListVdisk(), ParseCmdline(), Ping(), PrintDaclsOfFiles(), PrintError(), PrintFileDacl(), PrintLogonHours(), PrintMessageString(), PrintMessageStringV(), PrintNetMessage(), PrintPaddedMessageString(), PrintPadding(), PrintWin32Error(), PromptYesNo(), ReadPassword(), repair_main(), ShowConsoleCPStatus(), ShowConsoleStatus(), ShowHeader(), ShowParallelStatus(), ShowSerialStatus(), UnderlinedResPrintf(), unimplemented(), wmain(), and write_status().

◆ ConResMsgPrintf()

INT __cdecl ConResMsgPrintf ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN UINT  uID,
  ... 
)

Definition at line 1461 of file outstream.c.

1466 {
1467  INT Len;
1468  va_list args;
1469 
1470  /* Sanitize dwFlags */
1472 
1473  va_start(args, uID);
1474  Len = ConResMsgPrintfV(Stream, dwFlags, uID, &args);
1475  va_end(args);
1476 
1477  return Len;
1478 }
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
#define Len
Definition: deflate.h:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
INT ConResMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN UINT uID, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1329
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

◆ ConResMsgPrintfEx()

INT __cdecl ConResMsgPrintfEx ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN DWORD  dwFlags,
IN UINT  uID,
IN LANGID  LanguageId,
  ... 
)

Definition at line 1394 of file outstream.c.

1401 {
1402  INT Len;
1403  va_list args;
1404 
1405  /* Sanitize dwFlags */
1407 
1408  va_start(args, LanguageId);
1410  hInstance,
1411  dwFlags,
1412  uID,
1413  LanguageId,
1414  &args);
1415  va_end(args);
1416 
1417  return Len;
1418 }
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
INT ConResMsgPrintfExV(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN DWORD dwFlags, IN UINT uID, IN LANGID LanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1218
char * va_list
Definition: acmsvcex.h:78
#define Len
Definition: deflate.h:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

◆ ConResMsgPrintfExV()

INT ConResMsgPrintfExV ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN DWORD  dwFlags,
IN UINT  uID,
IN LANGID  LanguageId,
IN va_list *Arguments  OPTIONAL 
)

Definition at line 1218 of file outstream.c.

1225 {
1226  INT Len;
1227  DWORD dwLength = 0;
1228  LPWSTR lpMsgBuf = NULL;
1229  WCHAR bufSrc[CON_RC_STRING_MAX_SIZE];
1230 
1231  /* Retrieve the string from the resource string table */
1232  // NOTE: We may use the special behaviour where nBufMaxSize == 0
1233  Len = K32LoadStringExW(hInstance, uID, LanguageId, bufSrc, ARRAYSIZE(bufSrc));
1234  if (Len == 0)
1235  return Len;
1236 
1237  /* Sanitize dwFlags */
1238  dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer.
1239 
1240  /* The string has already been manually loaded */
1243 
1244  /*
1245  * Retrieve the message string without appending extra newlines.
1246  * Use the "safe" FormatMessage version (SEH-protected) to protect
1247  * from invalid string parameters.
1248  */
1250  bufSrc,
1251  0, 0,
1252  (LPWSTR)&lpMsgBuf,
1253  0,
1254  Arguments);
1255 
1256  Len = (INT)dwLength;
1257 
1258  if (!lpMsgBuf)
1259  {
1260  // ASSERT(dwLength == 0);
1261  }
1262  else
1263  {
1264  // ASSERT(dwLength != 0);
1265 
1266  CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len);
1267 
1268  /* Fixup returned length in case of errors */
1269  if (Len < 0)
1270  Len = 0;
1271 
1272  /* Free the buffer allocated by FormatMessage */
1273  LocalFree(lpMsgBuf);
1274  }
1275 
1276  return Len;
1277 }
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
#define INT
Definition: polytest.cpp:20
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
int32_t INT
Definition: typedefs.h:56
HINSTANCE hInstance
Definition: charmap.c:20
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
Definition: outstream.c:353
#define CON_RC_STRING_MAX_SIZE
Definition: outstream.c:56
__wchar_t WCHAR
Definition: xmlstorage.h:180
static DWORD DWORD * dwLength
Definition: fusion.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
WCHAR * LPWSTR
Definition: xmlstorage.h:184
DWORD WINAPI FormatMessageSafeW(IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, OUT LPWSTR lpBuffer, IN DWORD nSize, IN va_list *Arguments OPTIONAL)
Definition: utils.c:254
INT WINAPI K32LoadStringExW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:99
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by ConResMsgPrintfEx(), and ConResMsgPrintfV().

◆ ConResMsgPrintfV()

INT ConResMsgPrintfV ( IN PCON_STREAM  Stream,
IN DWORD  dwFlags,
IN UINT  uID,
IN va_list *Arguments  OPTIONAL 
)

Definition at line 1329 of file outstream.c.

1334 {
1335  return ConResMsgPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/,
1336  dwFlags, uID,
1338  Arguments);
1339 }
#define LANG_NEUTRAL
Definition: nls.h:22
#define SUBLANG_NEUTRAL
Definition: nls.h:167
INT ConResMsgPrintfExV(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN DWORD dwFlags, IN UINT uID, IN LANGID LanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1218
smooth NULL
Definition: ftsmooth.c:416
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define MAKELANGID(p, s)
Definition: nls.h:15
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by ConResMsgPrintf().

◆ ConResPrintf()

INT __cdecl ConResPrintf ( IN PCON_STREAM  Stream,
IN UINT  uID,
  ... 
)

Definition at line 781 of file outstream.c.

785 {
786  INT Len;
787  va_list args;
788 
789  va_start(args, uID);
790  Len = ConResPrintfV(Stream, uID, args);
791  va_end(args);
792 
793  return Len;
794 }
INT ConResPrintfV(IN PCON_STREAM Stream, IN UINT uID, IN va_list args)
Definition: outstream.c:695
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
#define Len
Definition: deflate.h:82
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by AddJob(), AddSubst(), CBindStatusCallback_OnProgress(), CheckLogOrSourceExistence(), ChkdskCallback(), cmdUse(), Confirm(), ConFormatMessage(), ConsoleCtrlHandler(), DeleteJob(), DeleteSubst(), EnumerateDevices(), FormatExCallback(), InputWait(), ListDisk(), ListPartition(), PagePrompt(), ParseCmdLine(), Ping(), print_err(), PrintAllJobs(), PrintError(), PrintJobDetails(), PrintStats(), ResolveTarget(), RunScript(), SelectDisk(), SelectPartition(), SerialPortQuery(), SetConsoleCPState(), SetConsoleState(), SetConsoleStateOld(), SetSerialState(), ShowConsoleCPStatus(), ShowConsoleStatus(), ShowEthernetStatistics(), ShowHeader(), ShowIcmpStatistics(), ShowIpStatistics(), ShowParallelStatus(), ShowSerialStatus(), ShowTcpStatistics(), ShowTcpTable(), ShowUdpStatistics(), Usage(), WlanPrintCurrentStatus(), WlanScan(), and wmain().

◆ ConResPrintfEx()

INT __cdecl ConResPrintfEx ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN UINT  uID,
IN LANGID  LanguageId,
  ... 
)

Definition at line 740 of file outstream.c.

746 {
747  INT Len;
748  va_list args;
749 
750  va_start(args, LanguageId);
751  Len = ConResPrintfExV(Stream, hInstance, uID, LanguageId, args);
752  va_end(args);
753 
754  return Len;
755 }
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
INT ConResPrintfExV(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, IN va_list args)
Definition: outstream.c:653
#define Len
Definition: deflate.h:82
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

◆ ConResPrintfExV()

INT ConResPrintfExV ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN UINT  uID,
IN LANGID  LanguageId,
IN va_list  args 
)

Definition at line 653 of file outstream.c.

659 {
660  INT Len;
662 
663  // NOTE: We may use the special behaviour where nBufMaxSize == 0
664  Len = K32LoadStringExW(hInstance, uID, LanguageId, bufSrc, ARRAYSIZE(bufSrc));
665  if (Len)
666  Len = ConPrintfV(Stream, bufSrc, args);
667 
668  return Len;
669 }
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
HINSTANCE hInstance
Definition: charmap.c:20
#define CON_RC_STRING_MAX_SIZE
Definition: outstream.c:56
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define Len
Definition: deflate.h:82
INT ConPrintfV(IN PCON_STREAM Stream, IN LPWSTR szStr, IN va_list args)
Definition: outstream.c:466
INT WINAPI K32LoadStringExW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:99
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by ConResPrintfEx(), and ConResPrintfV().

◆ ConResPrintfV()

INT ConResPrintfV ( IN PCON_STREAM  Stream,
IN UINT  uID,
IN va_list  args 
)

Definition at line 695 of file outstream.c.

699 {
700  return ConResPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/,
702  args);
703 }
#define LANG_NEUTRAL
Definition: nls.h:22
#define SUBLANG_NEUTRAL
Definition: nls.h:167
Definition: match.c:390
smooth NULL
Definition: ftsmooth.c:416
INT ConResPrintfExV(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, IN va_list args)
Definition: outstream.c:653
#define MAKELANGID(p, s)
Definition: nls.h:15
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by ConResPrintf(), PrintParserError(), and UnderlinedResPrintf().

◆ ConResPuts()

◆ ConResPutsEx()

INT ConResPutsEx ( IN PCON_STREAM  Stream,
IN HINSTANCE hInstance  OPTIONAL,
IN UINT  uID,
IN LANGID  LanguageId 
)

Definition at line 569 of file outstream.c.

574 {
575  INT Len;
576  PWCHAR szStr = NULL;
577 
578  Len = K32LoadStringExW(hInstance, uID, LanguageId, (PWSTR)&szStr, 0);
579  if (szStr && Len)
580  // Len = ConPuts(Stream, szStr);
581  CON_STREAM_WRITE2(Stream, szStr, Len, Len);
582 
583  /* Fixup returned length in case of errors */
584  if (Len < 0)
585  Len = 0;
586 
587  return Len;
588 }
uint16_t * PWSTR
Definition: typedefs.h:54
uint16_t * PWCHAR
Definition: typedefs.h:54
int32_t INT
Definition: typedefs.h:56
HINSTANCE hInstance
Definition: charmap.c:20
smooth NULL
Definition: ftsmooth.c:416
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
Definition: outstream.c:353
#define Len
Definition: deflate.h:82
INT WINAPI K32LoadStringExW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, IN LANGID LanguageId, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:99
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by ConResPuts().

◆ ConStreamWrite()

INT ConStreamWrite ( IN PCON_STREAM  Stream,
IN PTCHAR  szStr,
IN DWORD  len 
)

Definition at line 398 of file outstream.c.

402 {
403  INT Len;
404  CON_STREAM_WRITE2(Stream, szStr, len, Len);
405  return Len;
406 }
int32_t INT
Definition: typedefs.h:56
#define CON_STREAM_WRITE2(Stream, Str, Len, RetLen)
Definition: outstream.c:353
#define Len
Definition: deflate.h:82
GLenum GLsizei len
Definition: glext.h:6722
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092

Referenced by PagePrompt(), and UnderlinedResPrintf().

◆ ConWrite()

INT __stdcall ConWrite ( IN PCON_STREAM  Stream,
IN PTCHAR  szStr,
IN DWORD  len 
)

Definition at line 85 of file outstream.c.

89 {
90 #ifndef USE_CRT
91  DWORD TotalLen = len, dwNumBytes = 0;
92  PVOID p;
93 
94  /* If we do not write anything, just return */
95  if (!szStr || len == 0)
96  return 0;
97 
98  /* Check whether we are writing to a console */
99  // if (IsConsoleHandle(Stream->hHandle))
100  if (Stream->IsConsole)
101  {
102  // TODO: Check if (Stream->Mode == WideText or UTF16Text) ??
103 
104  /*
105  * This code is inspired from _cputws, in particular from the fact that,
106  * according to MSDN: https://msdn.microsoft.com/en-us/library/ms687401(v=vs.85).aspx
107  * the buffer size must be less than 64 KB.
108  *
109  * A similar code can be used for implementing _cputs too.
110  */
111 
112  DWORD cchWrite;
113  TotalLen = len, dwNumBytes = 0;
114 
115  while (len > 0)
116  {
117  cchWrite = min(len, 65535 / sizeof(WCHAR));
118 
119  // FIXME: Check return value!
120  WriteConsole(Stream->hHandle, szStr, cchWrite, &dwNumBytes, NULL);
121 
122  szStr += cchWrite;
123  len -= cchWrite;
124  }
125 
126  return (INT)TotalLen; // FIXME: Really return the number of chars written!
127  }
128 
129  /*
130  * We are redirected and writing to a file or pipe instead of the console.
131  * Convert the string from TCHARs to the desired output format, if the two differ.
132  *
133  * Implementation NOTE:
134  * MultiByteToWideChar (resp. WideCharToMultiByte) are equivalent to
135  * OemToCharBuffW (resp. CharToOemBuffW), but these latter functions
136  * uselessly depend on user32.dll, while MultiByteToWideChar and
137  * WideCharToMultiByte only need kernel32.dll.
138  */
139  if ((Stream->Mode == WideText) || (Stream->Mode == UTF16Text))
140  {
141 #ifndef _UNICODE // UNICODE means that TCHAR == WCHAR == UTF-16
142  /* Convert from the current process/thread's code page to UTF-16 */
144  if (!buffer)
145  {
147  return 0;
148  }
149  len = (DWORD)MultiByteToWideChar(CP_THREAD_ACP, // CP_ACP, CP_OEMCP
150  0, szStr, (INT)len, buffer, (INT)len);
151  szStr = (PVOID)buffer;
152 #else
153  /*
154  * Do not perform any conversion since we are already in UTF-16,
155  * that is the same encoding as the stream.
156  */
157 #endif
158 
159  /*
160  * Find any newline character in the buffer,
161  * write the part BEFORE the newline, then emit
162  * a carriage-return + newline sequence and finally
163  * write the remaining part of the buffer.
164  *
165  * This fixes output in files and serial console.
166  */
167  while (len > 0)
168  {
169  /* Loop until we find a newline character */
170  p = szStr;
171  while (len > 0 && *(PWCHAR)p != L'\n')
172  {
173  /* Advance one character */
174  p = (PVOID)((PWCHAR)p + 1);
175  --len;
176  }
177 
178  /* Write everything up to \n */
179  dwNumBytes = ((PWCHAR)p - (PWCHAR)szStr) * sizeof(WCHAR);
180  WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
181 
182  /*
183  * If we hit a newline and the previous character is not a carriage-return,
184  * emit a carriage-return + newline sequence, otherwise just emit the newline.
185  */
186  if (len > 0 && *(PWCHAR)p == L'\n')
187  {
188  if (p == (PVOID)szStr || (p > (PVOID)szStr && *((PWCHAR)p - 1) != L'\r'))
189  WriteFile(Stream->hHandle, L"\r\n", 2 * sizeof(WCHAR), &dwNumBytes, NULL);
190  else
191  WriteFile(Stream->hHandle, L"\n", sizeof(WCHAR), &dwNumBytes, NULL);
192 
193  /* Skip \n */
194  p = (PVOID)((PWCHAR)p + 1);
195  --len;
196  }
197  szStr = p;
198  }
199 
200 #ifndef _UNICODE
202 #endif
203  }
204  else if ((Stream->Mode == UTF8Text) || (Stream->Mode == AnsiText))
205  {
206  UINT CodePage;
207  PCHAR buffer;
208 
209  /*
210  * Resolve the current code page if it has not been assigned yet
211  * (we do this only if the stream is in ANSI mode; in UTF8 mode
212  * the code page is always set to CP_UTF8). Otherwise use the
213  * current stream's code page.
214  */
215  if (/*(Stream->Mode == AnsiText) &&*/ (Stream->CodePage == INVALID_CP))
216  CodePage = GetConsoleOutputCP(); // CP_ACP, CP_OEMCP
217  else
218  CodePage = Stream->CodePage;
219 
220 #ifdef _UNICODE // UNICODE means that TCHAR == WCHAR == UTF-16
221  /* Convert from UTF-16 to either UTF-8 or ANSI, using the stream code page */
222  // NOTE: MB_LEN_MAX defined either in limits.h or in stdlib.h .
224  if (!buffer)
225  {
227  return 0;
228  }
229  len = WideCharToMultiByte(CodePage, 0,
230  szStr, len, buffer, len * MB_LEN_MAX,
231  NULL, NULL);
232  szStr = (PVOID)buffer;
233 #else
234  /*
235  * Convert from the current process/thread's code page to either
236  * UTF-8 or ANSI, using the stream code page.
237  * We need to perform a double conversion, by going through UTF-16.
238  */
239  // TODO!
240  #error "Need to implement double conversion!"
241 #endif
242 
243  /*
244  * Find any newline character in the buffer,
245  * write the part BEFORE the newline, then emit
246  * a carriage-return + newline sequence and finally
247  * write the remaining part of the buffer.
248  *
249  * This fixes output in files and serial console.
250  */
251  while (len > 0)
252  {
253  /* Loop until we find a newline character */
254  p = szStr;
255  while (len > 0 && *(PCHAR)p != '\n')
256  {
257  /* Advance one character */
258  p = (PVOID)((PCHAR)p + 1);
259  --len;
260  }
261 
262  /* Write everything up to \n */
263  dwNumBytes = ((PCHAR)p - (PCHAR)szStr) * sizeof(CHAR);
264  WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
265 
266  /*
267  * If we hit a newline and the previous character is not a carriage-return,
268  * emit a carriage-return + newline sequence, otherwise just emit the newline.
269  */
270  if (len > 0 && *(PCHAR)p == '\n')
271  {
272  if (p == (PVOID)szStr || (p > (PVOID)szStr && *((PCHAR)p - 1) != '\r'))
273  WriteFile(Stream->hHandle, "\r\n", 2, &dwNumBytes, NULL);
274  else
275  WriteFile(Stream->hHandle, "\n", 1, &dwNumBytes, NULL);
276 
277  /* Skip \n */
278  p = (PVOID)((PCHAR)p + 1);
279  --len;
280  }
281  szStr = p;
282  }
283 
284 #ifdef _UNICODE
286 #else
287  // TODO!
288 #endif
289  }
290  else // if (Stream->Mode == Binary)
291  {
292  /* Directly output the string */
293  WriteFile(Stream->hHandle, szStr, len, &dwNumBytes, NULL);
294  }
295 
296  // FIXME!
297  return (INT)TotalLen;
298 
299 #else /* defined(USE_CRT) */
300 
301  DWORD total = len;
302  DWORD written = 0;
303 
304  /* If we do not write anything, just return */
305  if (!szStr || len == 0)
306  return 0;
307 
308 #if 1
309  /*
310  * There is no "counted" printf-to-stream or puts-like function, therefore
311  * we use this trick to output the counted string to the stream.
312  */
313  while (1)
314  {
315  written = fwprintf(Stream->fStream, L"%.*s", total, szStr);
316  if (written < total)
317  {
318  /*
319  * Some embedded NULL or special character
320  * was encountered, print it apart.
321  */
322  if (written == 0)
323  {
324  fputwc(*szStr, Stream->fStream);
325  written++;
326  }
327 
328  szStr += written;
329  total -= written;
330  }
331  else
332  {
333  break;
334  }
335  }
336  return (INT)len;
337 #else
338  /* ANSI text or Binary output only */
339  _setmode(_fileno(Stream->fStream), _O_TEXT); // _O_BINARY
340  return fwrite(szStr, sizeof(*szStr), len, Stream->fStream);
341 #endif
342 
343 #endif /* defined(USE_CRT) */
344 }
signed char * PCHAR
Definition: retypes.h:7
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define _setmode(fd, mode)
Definition: cat.c:21
#define WideCharToMultiByte
Definition: compat.h:101
unsigned long total
Definition: inflate.h:92
char CHAR
Definition: xmlstorage.h:175
#define INT
Definition: polytest.cpp:20
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
GLuint buffer
Definition: glext.h:5915
uint16_t * PWCHAR
Definition: typedefs.h:54
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
_Check_return_opt_ _CRTIMP int __cdecl fwprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const wchar_t *_Format,...)
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
Definition: console.c:2453
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define PCHAR
Definition: match.c:90
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define INVALID_CP
Definition: stream.h:53
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
#define _O_TEXT
Definition: cabinet.h:50
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define WriteConsole
Definition: wincon.h:772
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define MultiByteToWideChar
Definition: compat.h:100
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
GLfloat GLfloat p
Definition: glext.h:8902
#define CP_THREAD_ACP
Definition: winnls.h:230
_Check_return_opt_ _CRTIMP wint_t __cdecl fputwc(_In_ wchar_t _Ch, _Inout_ FILE *_File)
#define HeapFree(x, y, z)
Definition: compat.h:394
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
#define MB_LEN_MAX
Definition: limits.h:35

Referenced by ConErrChar(), ConOutChar(), ConStreamInit(), and ConStreamInitEx().