diff options
Diffstat (limited to 'src/fastd.h')
-rw-r--r-- | src/fastd.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/fastd.h b/src/fastd.h index e16cbb8..2a4e9ac 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -378,6 +378,8 @@ static inline size_t alignto(size_t l, size_t a) { return ((l+a-1)/a)*a; } +#define FASTD_BUFFER_NULL ((fastd_buffer_t){}) + static inline fastd_buffer_t fastd_buffer_alloc(const fastd_context_t *ctx, size_t len, size_t head_space, size_t tail_space) { size_t base_len = head_space+len+tail_space; void *ptr; @@ -387,6 +389,12 @@ static inline fastd_buffer_t fastd_buffer_alloc(const fastd_context_t *ctx, size return (fastd_buffer_t){ .base = ptr, .base_len = base_len, .data = ptr+head_space, .len = len }; } +static inline fastd_buffer_t fastd_buffer_dup(const fastd_context_t *ctx, fastd_buffer_t buffer, size_t head_space, size_t tail_space) { + fastd_buffer_t new_buffer = fastd_buffer_alloc(ctx, buffer.len, head_space, tail_space); + memcpy(new_buffer.data, buffer.data, buffer.len); + return new_buffer; +} + static inline void fastd_buffer_free(fastd_buffer_t buffer) { free(buffer.base); } |