You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
659 B
23 lines
659 B
/*! |
|
* \brief sdprintf printf to a dynamic buffer |
|
* \param buf The character buffer. Will append if not NULL; |
|
* \param offset Should be set to strlen when continuing a string. Will be incremented automatically. |
|
* \param __format printf format string |
|
* \return the number of bytes written |
|
*/ |
|
int sdprintf(char **buf, int *offset, const char *__restrict __format, ...) |
|
{ |
|
va_list vargs; |
|
int len; |
|
|
|
va_start(vargs, __format); |
|
len = vsnprintf(NULL, 0, __format, vargs); |
|
va_end(vargs); |
|
*buf = realloc(*buf, *offset + len + 1); |
|
va_start(vargs, __format); |
|
len = vsprintf(*buf + *offset, __format, vargs); |
|
va_end(vargs); |
|
|
|
*offset += len; |
|
return len; |
|
}
|
|
|