stdarg example
Code:
int my_snprintf(char *str,size_t size,const char *fmt,...)
{
int ret;
va_list ap;
va_start(ap,fmt);
ret = vsnprintf(str,size,fmt,ap);
// Whatever happen in vsnprintf, what i'll do is just to null terminate it
// and everything else s mynickmynick's problem
str[size-1] = '\0';
va_end(ap);
return ret;
}
After reading from msdn *nprintf documentation, there is another difference from standard *nprintf function.
msdn
1. If the number of characters to write exceeds count, then count characters are written and –1 is returned.
2. If buffer is a null pointer and count is nonzero, or format is a null pointer, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, these functions return -1 and set errno to EINVAL.
ansi
1. If the output was truncated due to this limit then the return value is the number of characters (not including the trailing '\0') which would have been written to the final string if enough space had been available.
2. C99 allows str to be NULL in this case, and gives the return value (as always) as the number of characters that would have been written in case the output string has been large enough.