summaryrefslogtreecommitdiffstats
path: root/common/mem.h
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2011-02-09 15:11:22 +0100
committerMarc-André Lureau <marcandre.lureau@gmail.com>2012-03-20 15:25:51 +0100
commit99a225c87a586264a6d1b61269cb3a3c0cea0afd (patch)
tree3d2c6e081fc31b58f7f84299ddd7eb0eeacc9216 /common/mem.h
parent7c98f5c94625e774c7b406d9f53922d476e2898d (diff)
downloadspice-common-99a225c87a586264a6d1b61269cb3a3c0cea0afd.tar.gz
spice-common-99a225c87a586264a6d1b61269cb3a3c0cea0afd.tar.xz
spice-common-99a225c87a586264a6d1b61269cb3a3c0cea0afd.zip
common: add SpiceBuffer - based on qemu-vnc Buffer
https://bugs.freedesktop.org/show_bug.cgi?id=34795
Diffstat (limited to 'common/mem.h')
-rw-r--r--common/mem.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/common/mem.h b/common/mem.h
index 5f0eb25..797bba0 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