From b87600cb6b80678f1ef8ca994785a4ba733c2133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 5 Sep 2011 02:33:02 +0200 Subject: buffer: add git_buf_clear MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set the size to zero so the memory that has already been allocated can be reused Signed-off-by: Carlos Martín Nieto --- src/buffer.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 6af4c9195..3cdc62f6d 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -93,3 +93,8 @@ void git_buf_free(git_buf *buf) { free(buf->ptr); } + +void git_buf_clear(git_buf *buf) +{ + buf->size = 0; +} -- cgit v1.2.1 From c7c3051328f605255c485cc49f58d16c7556d8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 5 Sep 2011 21:38:56 +0200 Subject: buffer: add git_buf_consume MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves the content after 'end' to the beginning of the buffer Signed-off-by: Carlos Martín Nieto --- src/buffer.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 3cdc62f6d..e92b2ef9e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -98,3 +98,10 @@ void git_buf_clear(git_buf *buf) { buf->size = 0; } + +void git_buf_consume(git_buf *buf, const char *end) +{ + size_t consumed = end - buf->ptr; + memmove(buf->ptr, end, buf->size - consumed); + buf->size -= consumed; +} -- cgit v1.2.1