|
|
udi_vsnprintf(3udi)
Format printable string with varargs
#include <udi.h>udi_size_t udi_vsnprintf ( char *s, udi_size_t max_bytes, const char *format, va_list ap );ARGUMENTS s is a pointer to the target buffer for the formatted output, which is a null-terminated printable string.
max_bytes is the maximum number of bytes to be written to s, including the null terminator.
format is the format string, which controls the formatting of the output string.
ap is the varags argument list. (The va_list type definition is provided by the udi.h header file.)
DESCRIPTION The udi_vsnprintf routine is used to generate a formatted string from a set of input varargs arguments. This utility operates in the same manner as the udi_snprintf utility routine except that it uses a previously obtained varargs argument list instead of a sequence of actual arguments as parameters to this routine.
This routine is useful if the string formatting is to be done from within a routine that has already been passed the actual sequence of arguments and can only refer to those arguments via the varargs functionality.
RETURN VALUES The number of bytes in s, not including the null terminator.
udi_size_t mydriver_snprintf(char *s,
udi_size_t max_bytes, const char *format, ...)
{
static char prefix_str[] = "From MYDRIVER: ";
#define PREFIX_LEN (sizeof(prefix_str)-1)
va_list arglist;
udi_size_t retval;
va_start(arglist, format);
udi_assert(max_bytes > PREFIX_LEN);
udi_strcpy(s, prefix_str);
retval = udi_vsnprintf(s + PREFIX_LEN,
max_bytes - PREFIX_LEN,
format, arglist);
va_end(arglist);
return retval;
}l = mydriver_snprintf("Byte 1 = %02bX, "
"pktlen = %hu\n", *pkt->data, pkt->len);