mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 20:29:27 +00:00
buffer: Add git_buf_vprintf
This commit is contained in:
parent
3fbcac89c4
commit
baaf1c4710
28
src/buffer.c
28
src/buffer.c
@ -146,17 +146,21 @@ int git_buf_puts(git_buf *buf, const char *string)
|
|||||||
return git_buf_put(buf, string, strlen(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;
|
int len;
|
||||||
va_list arglist;
|
|
||||||
|
|
||||||
ENSURE_SIZE(buf, buf->size + 1);
|
ENSURE_SIZE(buf, buf->size + (strlen(format) * 2));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
va_start(arglist, format);
|
va_list args;
|
||||||
len = p_vsnprintf(buf->ptr + buf->size, buf->asize - buf->size, format, arglist);
|
va_copy(args, ap);
|
||||||
va_end(arglist);
|
|
||||||
|
len = p_vsnprintf(
|
||||||
|
buf->ptr + buf->size,
|
||||||
|
buf->asize - buf->size,
|
||||||
|
format, args
|
||||||
|
);
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
git__free(buf->ptr);
|
git__free(buf->ptr);
|
||||||
@ -175,6 +179,18 @@ int git_buf_printf(git_buf *buf, const char *format, ...)
|
|||||||
return 0;
|
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)
|
void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
|
||||||
{
|
{
|
||||||
size_t copylen;
|
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_put(git_buf *buf, const char *data, size_t len);
|
||||||
int git_buf_puts(git_buf *buf, const char *string);
|
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_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_clear(git_buf *buf);
|
||||||
void git_buf_consume(git_buf *buf, const char *end);
|
void git_buf_consume(git_buf *buf, const char *end);
|
||||||
void git_buf_truncate(git_buf *buf, size_t len);
|
void git_buf_truncate(git_buf *buf, size_t len);
|
||||||
|
Loading…
Reference in New Issue
Block a user