Change kore_buf_appendv() to take a va_list

This commit is contained in:
Joris Vink 2014-04-22 12:16:21 +02:00
parent d2618db525
commit 39dd9d7972
2 changed files with 10 additions and 18 deletions

View File

@ -280,11 +280,6 @@ struct kore_buf {
u_int64_t offset;
};
struct buf_vec {
u_int8_t *data;
u_int32_t length;
};
struct kore_pool_region {
void *start;
LIST_ENTRY(kore_pool_region) list;
@ -455,7 +450,7 @@ struct kore_buf *kore_buf_create(u_int32_t);
void kore_buf_append(struct kore_buf *, void *, u_int32_t);
u_int8_t *kore_buf_release(struct kore_buf *, u_int32_t *);
void kore_buf_appendf(struct kore_buf *, const char *, ...);
void kore_buf_appendv(struct kore_buf *, struct buf_vec *, u_int16_t);
void kore_buf_appendv(struct kore_buf *, const char *, va_list);
void kore_buf_appendb(struct kore_buf *, struct kore_buf *);
void kore_buf_replace_string(struct kore_buf *, char *, void *, size_t);

View File

@ -53,29 +53,26 @@ kore_buf_appendb(struct kore_buf *buf, struct kore_buf *src)
}
void
kore_buf_appendv(struct kore_buf *buf, struct buf_vec *v, u_int16_t count)
kore_buf_appendv(struct kore_buf *buf, const char *fmt, va_list args)
{
u_int16_t i;
struct buf_vec *p;
int l;
char b[4096];
p = v;
for (i = 0; i < count; i++) {
kore_buf_append(buf, p->data, p->length);
p++;
}
l = vsnprintf(b, sizeof(b), fmt, args);
if (l == -1 || (size_t)l >= sizeof(b))
fatal("kore_buf_appendv(): error or truncation");
kore_buf_append(buf, (u_int8_t *)b, l);
}
void
kore_buf_appendf(struct kore_buf *buf, const char *fmt, ...)
{
va_list args;
char b[2048];
va_start(args, fmt);
vsnprintf(b, sizeof(b), fmt, args);
kore_buf_appendv(buf, fmt, args);
va_end(args);
kore_buf_append(buf, (u_int8_t *)b, strlen(b));
}
u_int8_t *