xprintf d727b10
xsprintf.h File Reference

The xsnprintf() and xvsnprintf() functions are equivalent to ISO C99's snprintf() and vsnprintf(). More...

Functions

int xsnprintf (char *restrict str, size_t size, const char *restrict format,...) __attribute__((format(printf
 The xsnprintf() function is equivalent to ISO C99's snprintf().
int int xvsnprintf (char *restrict str, size_t size, const char *restrict format, va_list ap)
 The xvsnprintf() function is equivalent to ISO C99's vsnprintf().

Detailed Description

The xsnprintf() and xvsnprintf() functions are equivalent to ISO C99's snprintf() and vsnprintf().

The functions behave as xprintf(), except that the output is written into an array (specified by argument str) rather than to a channel.

If size is zero, nothing is written, and str may be a null pointer. Otherwise, output characters beyond the size-1st are discarded rather than being written to the array, and a null character is written at the end of the characters actually written into the array.

Thus, the null terminated output has been completely written if and only if the returned value is nonnegative and less than size.


Function Documentation

int xsnprintf ( char *restrict  str,
size_t  size,
const char *restrict  format,
  ... 
)

The xsnprintf() function is equivalent to ISO C99's snprintf().

Parameters:
strpointer to destination buffer
sizesizeof str
formata printf() compatible format string
...variable argument list for format
Returns:
<0: error code
≥0: the number of characters that would have been written had size been sufficiently large, not counting the terminating null character
See also:
snprintf() specification in ISO C99
int int xvsnprintf ( char *restrict  str,
size_t  size,
const char *restrict  format,
va_list  ap 
)

The xvsnprintf() function is equivalent to ISO C99's vsnprintf().

Parameters:
strpointer to destination buffer
sizesizeof str
formata printf() compatible format string
apva_list to the arguments for format
Returns:
<0: error code
≥0: the number of characters that would have been written had size been sufficiently large, not counting the terminating null character
See also:
vsnprintf() specification in ISO C99