diff options
Diffstat (limited to 'src/std/buffer.c')
-rw-r--r-- | src/std/buffer.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/std/buffer.c b/src/std/buffer.c index 3fc5184..42b1a0f 100644 --- a/src/std/buffer.c +++ b/src/std/buffer.c @@ -1,4 +1,5 @@ #include "../../include/std/buffer.h" +#include <stdio.h> #include <stdlib.h> #include <string.h> @@ -25,18 +26,28 @@ static int tsl_buffer_ensure_capacity(TslBuffer *self, size_t new_size) { new_size = new_capacity; } new_ptr = realloc(self->data, new_size); - if(!new_ptr) + if(!new_ptr) { + fprintf(stderr, "Error: buffer append failed. Reason: out of memory\n"); return 0; + } self->data = new_ptr; self->capacity = new_size; return 1; } -int tsl_buffer_append(TslBuffer *self, void *data, size_t size) { +int tsl_buffer_append(TslBuffer *self, const void *data, size_t size) { if(!tsl_buffer_ensure_capacity(self, self->size + size)) - return 1; + return 0; memcpy((char*)self->data + self->size, data, size); self->size += size; - return 0; + return 1; +} + +void* tsl_buffer_begin(TslBuffer *self) { + return self->data; +} + +void* tsl_buffer_end(TslBuffer *self) { + return (char*)self->data + self->size; } |