summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-19 10:05:33 -0500
committerEdward Thomson <ethomson@microsoft.com>2015-02-19 10:05:33 -0500
commitd4cf167515d3ed7b27c1358fc2e19b9caf66e8ad (patch)
treeecb73c7055ea0a319f72996517f966c904bd5100 /src/buffer.c
parentb49edddcd0af70caee7eb4905dc26199adccabfd (diff)
downloadlibgit2-d4cf167515d3ed7b27c1358fc2e19b9caf66e8ad.tar.gz
buffer: introduce git_buf_attach_notowned
Provide a convenience function that creates a buffer that can be provided to callers but will not be freed via `git_buf_free`, so the buffer creator maintains the allocation lifecycle of the buffer's contents.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 3deb0329c..f633c5e02 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -500,6 +500,20 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize)
}
}
+void git_buf_attach_notowned(git_buf *buf, const char *ptr, size_t size)
+{
+ if (git_buf_is_allocated(buf))
+ git_buf_free(buf);
+
+ if (!size) {
+ git_buf_init(buf, 0);
+ } else {
+ buf->ptr = (char *)ptr;
+ buf->asize = 0;
+ buf->size = size;
+ }
+}
+
int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
{
va_list ap;