libgit2

git_buf_grow

Version:

Resize the buffer allocation to make more space.

This will attempt to grow the buffer to accomodate the target size.

If the buffer refers to memory that was not allocated by libgit2 (i.e. the asize field is zero), then ptr will be replaced with a newly allocated block of data. Be careful so that memory allocated by the caller is not lost. As a special variant, if you pass target_size as 0 and the memory is not allocated by libgit2, this will allocate a new buffer of size size and copy the external data into it.

Currently, this will never shrink a buffer, only expand it.

If the allocation fails, this will return an error and the buffer will be marked as invalid for future operations, invaliding the contents.

Signature

int git_buf_grow(git_buf *buffer, size_t target_size);

Parameters

In
buffer

The buffer to be resized; may or may not be allocated yet

size_t
In
target_size

The desired available size

Returns

int

0 on success, -1 on allocation failure

Versions