aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buffer.c7
-rw-r--r--buffer.h3
2 files changed, 10 insertions, 0 deletions
diff --git a/buffer.c b/buffer.c
index bc77f7f..1304098 100644
--- a/buffer.c
+++ b/buffer.c
@@ -168,3 +168,10 @@ const char *buffer_content0(Buffer *buf) {
return "";
return buf->data;
}
+
+char *buffer_move(Buffer *buf) {
+ char *data = buf->data;
+ buffer_clear(buf);
+ buf->data = NULL;
+ return data;
+}
diff --git a/buffer.h b/buffer.h
index 41c2532..1bb20d7 100644
--- a/buffer.h
+++ b/buffer.h
@@ -57,5 +57,8 @@ size_t buffer_capacity(Buffer*);
const char *buffer_content0(Buffer*);
/* pointer to buffer data, might be NULL if empty, might not be NUL terminated */
const char *buffer_content(Buffer*);
+/* steal underlying buffer data, caller is responsible to free(3) it,
+ * similar to move semantics in some programming languages */
+char *buffer_move(Buffer*);
#endif