summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-07-01 10:20:38 -0700
committerRussell Belfer <rb@github.com>2013-07-01 10:20:38 -0700
commit278ce7468d3870bb18d69bd8177bae406d6cede4 (patch)
tree9e00f07d6d12ed41a35973f882703d1084842cbd /src/buffer.c
parentc61300eda94eedb53f072fedbf1bb52be21ca221 (diff)
downloadlibgit2-278ce7468d3870bb18d69bd8177bae406d6cede4.tar.gz
Add helpful buffer shorten function
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 6e3ffe560..b5b2fd678 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -259,6 +259,15 @@ void git_buf_truncate(git_buf *buf, size_t len)
}
}
+void git_buf_shorten(git_buf *buf, size_t amount)
+{
+ if (amount > buf->size)
+ amount = buf->size;
+
+ buf->size = buf->size - amount;
+ buf->ptr[buf->size] = '\0';
+}
+
void git_buf_rtruncate_at_char(git_buf *buf, char separator)
{
ssize_t idx = git_buf_rfind_next(buf, separator);