diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-08-20 16:01:22 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-08-20 16:11:19 +0200 |
| commit | c7df560b818224d9a9ca3b0ba31a54312dc7062b (patch) | |
| tree | 370fc6ba645eb2506c592a76e97ac51320bc1e3b /buffer.c | |
| parent | 2b4a550d432e5e570bb888ce06440a825c2e2e7c (diff) | |
| download | vis-c7df560b818224d9a9ca3b0ba31a54312dc7062b.tar.gz vis-c7df560b818224d9a9ca3b0ba31a54312dc7062b.tar.xz | |
buffer: add buffer_remove implementation
Diffstat (limited to 'buffer.c')
| -rw-r--r-- | buffer.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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; |
