buf API changes.

- rename kore_buf_destroy() to kore_buf_cleanup().
- rename kore_buf_create() to kore_buf_alloc().
This commit is contained in:
Joris Vink 2016-07-14 12:33:13 +02:00
parent 3b0477cf97
commit b28b60c2ff
2 changed files with 10 additions and 6 deletions

View File

@ -622,12 +622,12 @@ void net_send_stream(struct connection *, void *,
size_t, int (*cb)(struct netbuf *), struct netbuf **); size_t, int (*cb)(struct netbuf *), struct netbuf **);
void kore_buf_free(struct kore_buf *); 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_init(struct kore_buf *, size_t);
void kore_buf_append(struct kore_buf *, const void *, size_t); void kore_buf_append(struct kore_buf *, const void *, size_t);
u_int8_t *kore_buf_release(struct kore_buf *, size_t *); u_int8_t *kore_buf_release(struct kore_buf *, size_t *);
void kore_buf_reset(struct kore_buf *); 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 *); char *kore_buf_stringify(struct kore_buf *, size_t *);
void kore_buf_appendf(struct kore_buf *, const char *, ...); void kore_buf_appendf(struct kore_buf *, const char *, ...);

View File

@ -22,7 +22,7 @@
#include "kore.h" #include "kore.h"
struct kore_buf * struct kore_buf *
kore_buf_create(size_t initial) kore_buf_alloc(size_t initial)
{ {
struct kore_buf *buf; struct kore_buf *buf;
@ -35,7 +35,11 @@ kore_buf_create(size_t initial)
void void
kore_buf_init(struct kore_buf *buf, size_t initial) 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->length = initial;
buf->offset = 0; 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"); fatal("overflow in kore_buf_append");
if ((buf->offset + len) > buf->length) { if ((buf->offset + len) > buf->length) {
buf->length += len + KORE_BUF_INCREMENT; buf->length += len;
buf->data = kore_realloc(buf->data, buf->length); buf->data = kore_realloc(buf->data, buf->length);
} }
@ -133,7 +137,7 @@ kore_buf_free(struct kore_buf *buf)
} }
void void
kore_buf_destroy(struct kore_buf *buf) kore_buf_cleanup(struct kore_buf *buf)
{ {
if (buf->data) if (buf->data)
kore_free(buf->data); kore_free(buf->data);