Commit baaf1c47 by Vicent Martí

buffer: Add `git_buf_vprintf`

parent 3fbcac89
......@@ -146,17 +146,21 @@ int git_buf_puts(git_buf *buf, const char *string)
return git_buf_put(buf, string, strlen(string));
}
int git_buf_printf(git_buf *buf, const char *format, ...)
int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
{
int len;
va_list arglist;
ENSURE_SIZE(buf, buf->size + 1);
ENSURE_SIZE(buf, buf->size + (strlen(format) * 2));
while (1) {
va_start(arglist, format);
len = p_vsnprintf(buf->ptr + buf->size, buf->asize - buf->size, format, arglist);
va_end(arglist);
va_list args;
va_copy(args, ap);
len = p_vsnprintf(
buf->ptr + buf->size,
buf->asize - buf->size,
format, args
);
if (len < 0) {
git__free(buf->ptr);
......@@ -175,6 +179,18 @@ int git_buf_printf(git_buf *buf, const char *format, ...)
return 0;
}
int git_buf_printf(git_buf *buf, const char *format, ...)
{
int r;
va_list ap;
va_start(ap, format);
r = git_buf_vprintf(buf, format, ap);
va_end(ap);
return r;
}
void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
{
size_t copylen;
......
......@@ -76,6 +76,7 @@ int git_buf_putc(git_buf *buf, char c);
int git_buf_put(git_buf *buf, const char *data, size_t len);
int git_buf_puts(git_buf *buf, const char *string);
int git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
int git_buf_vprintf(git_buf *buf, const char *format, va_list ap);
void git_buf_clear(git_buf *buf);
void git_buf_consume(git_buf *buf, const char *end);
void git_buf_truncate(git_buf *buf, size_t len);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment