diff options
author | Russell Belfer <rb@github.com> | 2013-07-01 10:20:38 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-07-01 10:20:38 -0700 |
commit | 278ce7468d3870bb18d69bd8177bae406d6cede4 (patch) | |
tree | 9e00f07d6d12ed41a35973f882703d1084842cbd /src/buffer.c | |
parent | c61300eda94eedb53f072fedbf1bb52be21ca221 (diff) | |
download | libgit2-278ce7468d3870bb18d69bd8177bae406d6cede4.tar.gz |
Add helpful buffer shorten function
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 9 |
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); |