chsvlib
chsv helper source code

◆ snPrintfA_s()

int Chusov::String::snPrintfA_s ( char *restrict  pDest,
rsize_t  cchDest,
const char *restrict  pszFormat,
  ... 
)
noexcept

The function behaves identically to snPrintfA but with security constraints.

Parameters
[out]pDestis a pointer to the output buffer where the converted string is to be written to. A size, in bytes, of the buffer is specified by cchDest. pDest must not be NULL.
[in]cchDestis a size, in bytes, of the output buffer. cchDest must not be zero. At most \((cchDest - 1)\) bytes of the formatted string are written to the output buffer. A zero terminator is always appended to the end of the output string.
[in]pszFormatis a pointer to a zero terminated string defining how to interpret data, passed as additional parameters, during construction of the output. See PrintfA_s for the definition of the format lexemes.
...constitute an optional set of additional parameters to build the formatted output according to pszFormat.
Returns
On success the function returns a number of bytes that would have been written had cchDest been sufficiently large, not counting the terminating zero. If an error or a runtime constraint violation occurs the function returns a negative number setting the corresponding errno code. Thus an output string has been completely written to the output buffer if and only if the function returns a nonnegative number strictly less than cchDest.

Unlike the sPrintfA_s function, if cchDest is less than a size required to hold the whole output string, the function will not fail but will truncate the result to fit the available space.

The snPrintfA_s function is equivalent to snPrintfA except for the following explicit runtime constraints specified by ISO/IEC TR 24731-1:

  1. Neither pDest nor pszFormat can be NULL.
  2. The size cchDest must neither be equal to zero nor be greater than RSIZE_MAX.
  3. The 'n' type specifier must not appear in a set of conversion specifiers (see PrintfA and PrintfA_s).
  4. 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 errno to EINVAL.

On error, if pDest is not null and cchDest is greater than 0 and less than RSIZE_MAX, the function sets pDest[0] to the null character.

See also
PrintfA_s;
snPrintfW_s;
snPrintfA.