forked from mirrors/kore
Added kore_buf no alloc functions.
kore_buf_create and kore_buf_free do use kore_malloc. But sometimes you may embed a kore_buf inside a structure and would like a single way to initialize / destroy it.
This commit is contained in:
parent
a07cf87b15
commit
db3cf28d22
|
@ -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 *, ...);
|
||||
|
|
20
src/buf.c
20
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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue