chsvlib
chsv helper source code

◆ vscPrintfW_s()

int Chusov::String::vscPrintfW_s ( const wchar_t *restrict  pszFormat,
va_list  ap 
)
noexcept

Returns a number of wide characters required to hold a string, given by formatting parameters, not counting the terminating zero. The function behaves identically to scPrintfW but with security constraints.

Parameters
[in]pszFormatis a pointer to a zero terminated wide string defining how to interpret data, passed as additional parameters, during the construction of the output. See PrintfW_s for the definition of the format lexemes.
[in]apis a variable argument list containing data used to construct an output string according to the format.
Returns
On success the function returns a number of wide characters required to hold the formatted string except for the terminating null. On failure the function returns a negative number.

The function is introduced to provide a possibility to preallocate a buffer of a required size before calling a function that actually creates a formatted output.

The function is intended for use with the so called "secure" functions defined by the ISO/IEC TR 24731-1 standard specifying certain runtime constraints. For the standard C functions that do not require a satisfaction to the "secure" runtime constraints use the scPrintfW function.

The function is a chsvlib extension over the functions of the PrintfW_s family that are implemented according to the ISO/IEC TR 24731-1 standard and have explicitly given equivalents defined by the standard. The function has an equivalent implemented as a part of Microsoft C Library - _vswcprintf.

The runtime constraints, defined by the ISO/IEC TR 24731-1 standard, are:

  1. The pszFormat pointer cannot be NULL.
  2. The 'n' type specifier must not appear in a set of conversion specifiers (see PrintfA and PrintfA_s).
  3. Any pointer corresponding to 's' or 'S' type specifiers must not be NULL.

If any of the constraints is violated the function generates an assertion and, if the execution is allowed to continue, returns a negative number setting corresponding errno code

See also
PrintfW_s;
vscPrintfA_s;
vscPrintfW.