diff --git a/includes/kore.h b/includes/kore.h index 9805165..2d78462 100644 --- a/includes/kore.h +++ b/includes/kore.h @@ -621,9 +621,11 @@ void net_send_stream(struct connection *, void *, void kore_buf_free(struct kore_buf *); struct kore_buf *kore_buf_create(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 *); 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 6920486..e46fec7 100644 --- a/src/buf.c +++ b/src/buf.c @@ -27,11 +27,17 @@ kore_buf_create(size_t initial) struct kore_buf *buf; buf = kore_malloc(sizeof(*buf)); + kore_buf_init(buf, initial); + + return (buf); +} + +void +kore_buf_init(struct kore_buf *buf, size_t initial) +{ buf->data = kore_malloc(initial); buf->length = initial; buf->offset = 0; - - return (buf); } void @@ -126,6 +132,16 @@ kore_buf_free(struct kore_buf *buf) kore_mem_free(buf); } +void +kore_buf_destroy(struct kore_buf *buf) +{ + if (buf->data) + kore_mem_free(buf->data); + buf->data = NULL; + buf->offset = 0; + buf->length = 0; +} + void kore_buf_replace_string(struct kore_buf *b, char *src, void *dst, size_t len) {