aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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