aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-09-13 17:36:28 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-09-15 09:08:54 +0200
commitf20ea432e67d3b0223129b418613c74b3beae450 (patch)
tree92ef9daf88129e65662d805a788c81a0c9ae49e4
parent4cb296f155191a0de0d0a67995813526b6a4287b (diff)
downloadvis-f20ea432e67d3b0223129b418613c74b3beae450.tar.gz
vis-f20ea432e67d3b0223129b418613c74b3beae450.tar.xz
buffer: add buffer_append0 to append NUL terminated strings
-rw-r--r--buffer.c6
-rw-r--r--buffer.h2
2 files changed, 8 insertions, 0 deletions
diff --git a/buffer.c b/buffer.c
index 1a3c7db..05e8177 100644
--- 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
index ef5a537..23a92ba 100644
--- 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