kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 39dd9d79726cc2ee7a6d94521c93a321100fcef0
parent d2618db525a57574d4ad7be617eb8754218f8317
Author: Joris Vink <joris@coders.se>
Date:   Tue, 22 Apr 2014 12:16:21 +0200

Change kore_buf_appendv() to take a va_list

Diffstat:
includes/kore.h | 7+------
src/buf.c | 21+++++++++------------
2 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -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); diff --git a/src/buf.c b/src/buf.c @@ -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 *