vsnprintf() — Format and print data to fixed length buffer
Format
#include <stdarg.h>
#include <stdio.h>
int vsnprintf(char *__restrict__ s, size_t n,
const char *__restrict__ format, va_list arg);
General Description
The vsnprintf() function is equivalent to snprintf(), except that instead of being called with a variable number of arguments, it is called with an argument list as defined by stdarg.h. For a specification of the format string, see sprintf() — Format and Write Data.
Initialize the argument
list by using the va_start
macro before each call.
These functions do not invoke the va_end
macro, but
instead invoke the va_arg
macro causing the value
of arg after the return to be unspecified.
- Use of vsnprintf() requires that an environment has been set up by using the __cinit() function. When the function is called, GPR 12 must contain the environment token created by the __cinit() call.
- In contrast to some UNIX-based implementations of the C language, the z/OS® XL C/C++ implementation
of the vprintf() family increments the pointer to the variable arguments
list. To control whether the pointer is incremented, call the
va_end
macro after each function call.
Returned Value
The vsnprintf() function returns the number of characters that would have been written had n been sufficiently large, not counting the terminating null character, or a negative value if an encoding error occurred. Thus, the null-terminated output has been completely written if and only if the returned value is nonnegative and less than n.