2 changed files with 25 additions and 2 deletions
@ -0,0 +1,23 @@
|
||||
/*!
|
||||
* \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; |
||||
} |
Loading…
Reference in new issue