From 2bbb4fca0c97043b183fb65126b7198bc0750a78 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 9 Feb 2011 15:11:22 +0100 Subject: common: add SpiceBuffer - based on qemu-vnc Buffer https://bugs.freedesktop.org/show_bug.cgi?id=34795 --- common/mem.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'common/mem.h') diff --git a/common/mem.h b/common/mem.h index 5f0eb25e..797bba0a 100644 --- a/common/mem.h +++ b/common/mem.h @@ -39,6 +39,13 @@ typedef struct SpiceChunks { SpiceChunk chunk[0]; } SpiceChunks; +typedef struct SpiceBuffer +{ + size_t capacity; + size_t offset; + uint8_t *buffer; +} SpiceBuffer; + char *spice_strdup(const char *str) SPICE_GNUC_MALLOC; char *spice_strndup(const char *str, size_t n_bytes) SPICE_GNUC_MALLOC; void *spice_memdup(const void *mem, size_t n_bytes) SPICE_GNUC_MALLOC; @@ -103,4 +110,14 @@ size_t spice_strnlen(const char *str, size_t max_len); #define spice_new0(struct_type, n_structs) _SPICE_NEW(struct_type, n_structs, malloc0) #define spice_renew(struct_type, mem, n_structs) _SPICE_RENEW(struct_type, mem, n_structs, realloc) +/* Buffer management */ +void spice_buffer_reserve(SpiceBuffer *buffer, size_t len); +int spice_buffer_empty(SpiceBuffer *buffer); +uint8_t *spice_buffer_end(SpiceBuffer *buffer); +void spice_buffer_reset(SpiceBuffer *buffer); +void spice_buffer_free(SpiceBuffer *buffer); +void spice_buffer_append(SpiceBuffer *buffer, const void *data, size_t len); +size_t spice_buffer_copy(SpiceBuffer *buffer, void *dest, size_t len); +size_t spice_buffer_remove(SpiceBuffer *buffer, size_t len); + #endif -- cgit