vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit e2d2a83e07a8b54e8746c2114eb88afc8e18e225
parent 400d8a392a5a02fd7c9a0117b7716081858755a0
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun, 13 Sep 2015 17:36:28 +0200

buffer: add buffer_append0 to append NUL terminated strings

Diffstat:
Mbuffer.c | 6++++++
Mbuffer.h | 2++
2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/buffer.c b/buffer.c @@ -52,3 +52,9 @@ bool buffer_append(Buffer *buf, const void *data, size_t len) { buf->len += len; return true; } + +bool buffer_append0(Buffer *buf, const char *data) { + if (buf->len > 0 && buf->data[buf->len-1] == '\0') + buf->len--; + return buffer_append(buf, data, strlen(data)) && buffer_append(buf, "\0", 1); +} diff --git a/buffer.h b/buffer.h @@ -23,5 +23,7 @@ void buffer_truncate(Buffer*); bool buffer_put(Buffer*, const void *data, size_t len); /* append futher content to the end of the buffer data */ bool buffer_append(Buffer*, const void *data, size_t len); +/* append NUl-terminated data */ +bool buffer_append0(Buffer*, const char *data); #endif