The truncating vsnprintf_s function composes a string with same test that would be printed if format was used on printf.
Instead of being printed, the content is stored in dest. Warning: Unlike the safe variant vsprintf_s, vsnprintf_s does not guarantee that the buffer will be null-terminated unless the buffer size is zero. More than dmax - 1 characters might be written!
- Note
- POSIX specifies that
errno is set on error. However, the safeclib extended ES* errors do not set errno, only when the underlying system vsnprintf call fails, errno is set.
- Parameters
-
| [out] | dest | pointer to string that will be written into. |
| [in] | dmax | restricted maximum length of dest |
| [in] | fmt | format-control string. |
| [in] | ap | optional arguments |
- Precondition
- Neither
dest nor fmt shall be a null pointer.
-
dmax shall not be greater than RSIZE_MAX_STR.
-
dmax shall not equal zero.
-
dmax shall be greater than strnlen_s(dest, dmax).
-
fmt shall not contain the conversion specifier n.
-
None of the arguments corresponding to
s is a null pointer. (not yet)
-
No encoding error shall occur.
- Note
- C11 uses RSIZE_MAX, not RSIZE_MAX_STR.
- Returns
- On success the total number of characters written is returned.
-
On failure a negative number is returned.
-
If the buffer
dest is too small for the formatted text, including the terminating null, then the buffer is set to an empty string by placing a null character at dest[0], and the invalid parameter handler is invoked. Unlike vsnprintf, vsprintf_s guarantees that the buffer will be null-terminated unless the buffer size is zero.
- Return values
-
| -ESNULLP | when dest/fmt is NULL pointer |
| -ESZEROL | when dmax = 0 |
| -ESLEMAX | when dmax > RSIZE_MAX_STR |
| -EINVAL | when fmt contains n |
- See also
- sprintf_s(), vsprintf_s()