From b28b60c2ff6d66b503bd31acedfb48070ad99922 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Thu, 14 Jul 2016 12:33:13 +0200 Subject: [PATCH] buf API changes. - rename kore_buf_destroy() to kore_buf_cleanup(). - rename kore_buf_create() to kore_buf_alloc(). --- includes/kore.h | 4 ++-- src/buf.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/kore.h b/includes/kore.h index cc4b038..bfa11c8 100644 --- a/includes/kore.h +++ b/includes/kore.h @@ -622,12 +622,12 @@ void net_send_stream(struct connection *, void *, size_t, int (*cb)(struct netbuf *), struct netbuf **); void kore_buf_free(struct kore_buf *); -struct kore_buf *kore_buf_create(size_t); +struct kore_buf *kore_buf_alloc(size_t); void kore_buf_init(struct kore_buf *, size_t); void kore_buf_append(struct kore_buf *, const void *, size_t); u_int8_t *kore_buf_release(struct kore_buf *, size_t *); void kore_buf_reset(struct kore_buf *); -void kore_buf_destroy(struct kore_buf *); +void kore_buf_cleanup(struct kore_buf *); char *kore_buf_stringify(struct kore_buf *, size_t *); void kore_buf_appendf(struct kore_buf *, const char *, ...); diff --git a/src/buf.c b/src/buf.c index b7b42a9..5351584 100644 --- a/src/buf.c +++ b/src/buf.c @@ -22,7 +22,7 @@ #include "kore.h" struct kore_buf * -kore_buf_create(size_t initial) +kore_buf_alloc(size_t initial) { struct kore_buf *buf; @@ -35,7 +35,11 @@ kore_buf_create(size_t initial) void kore_buf_init(struct kore_buf *buf, size_t initial) { - buf->data = kore_malloc(initial); + if (initial > 0) + buf->data = kore_malloc(initial); + else + buf->data = NULL; + buf->length = initial; buf->offset = 0; } @@ -47,7 +51,7 @@ kore_buf_append(struct kore_buf *buf, const void *d, size_t len) fatal("overflow in kore_buf_append"); if ((buf->offset + len) > buf->length) { - buf->length += len + KORE_BUF_INCREMENT; + buf->length += len; buf->data = kore_realloc(buf->data, buf->length); } @@ -133,7 +137,7 @@ kore_buf_free(struct kore_buf *buf) } void -kore_buf_destroy(struct kore_buf *buf) +kore_buf_cleanup(struct kore_buf *buf) { if (buf->data) kore_free(buf->data);