aboutsummaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-08-20 16:01:22 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-08-20 16:11:19 +0200
commitc7df560b818224d9a9ca3b0ba31a54312dc7062b (patch)
tree370fc6ba645eb2506c592a76e97ac51320bc1e3b /buffer.c
parent2b4a550d432e5e570bb888ce06440a825c2e2e7c (diff)
downloadvis-c7df560b818224d9a9ca3b0ba31a54312dc7062b.tar.gz
vis-c7df560b818224d9a9ca3b0ba31a54312dc7062b.tar.xz
buffer: add buffer_remove implementation
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/buffer.c b/buffer.c
index b3c05d6..abf3ab7 100644
--- a/buffer.c
+++ b/buffer.c
@@ -59,6 +59,16 @@ bool buffer_put0(Buffer *buf, const char *data) {
return buffer_put(buf, data, strlen(data)+1);
}
+bool buffer_remove(Buffer *buf, size_t pos, size_t len) {
+ if (len == 0)
+ return true;
+ if (pos + len > buf->len)
+ return false;
+ memmove(buf->data + pos, buf->data + pos + len, buf->len - pos - len);
+ buf->len -= len;
+ return true;
+}
+
bool buffer_insert(Buffer *buf, size_t pos, const void *data, size_t len) {
if (pos > buf->len)
return false;