safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
sprintf_s.c File Reference
#include "safe_str_lib.h"
+ Include dependency graph for sprintf_s.c:

Functions

EXPORT int sprintf_s (char *restrict dest, rsize_t dmax, const char *restrict fmt,...)
 The sprintf_s function composes a string with same test that would be printed if format was used on printf. More...
 

Function Documentation

◆ sprintf_s()

EXPORT int sprintf_s ( char *restrict  dest,
rsize_t  dmax,
const char *restrict  fmt,
  ... 
)

The sprintf_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.

Remarks
SPECIFIED IN
Parameters
[out]deststorage location for output buffer.
[in]dmaxmaximum number of characters to store in buffer.
[in]fmtformat-control string.
[in]...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.
Returns
If no runtime-constraint violation occurred, the sprintf_s function returns the number of characters written in the array, not counting the terminating null character. If an encoding error occurred, sprintf_s returns a negative value. If any other runtime- constraint violation in vsnprintf occurred, sprintf_s returns zero.
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 _snprintf, sprintf_s guarantees that the buffer will be null-terminated unless the buffer size is zero.

errno: ESNULLP when dest/fmt is NULL pointer ESZEROL when dmax = 0 ESLEMAX when dmax > RSIZE_MAX_STR ESNOSPC when return value exceeds dmax EINVAL when fmt contains n

Return values
-1if an encoding error occurred or the return buffer size exceeds dmax.
0on some other error in vsnprintf().