Skip to content

Commit db6bdf2

Browse files
committed
Add rbs_buffer_init_with_capacity
1 parent 76c06b8 commit db6bdf2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

include/rbs/util/rbs_buffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ typedef struct {
3131
*/
3232
bool rbs_buffer_init(rbs_allocator_t *, rbs_buffer_t *buffer);
3333

34+
bool rbs_buffer_init_with_capacity(rbs_allocator_t *allocator, rbs_buffer_t *buffer, size_t capacity);
35+
3436
/**
3537
* Return the value of the buffer.
3638
*

src/util/rbs_buffer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
#define RBS_BUFFER_DEFAULT_CAPACITY 128
99

1010
bool rbs_buffer_init(rbs_allocator_t *allocator, rbs_buffer_t *buffer) {
11+
return rbs_buffer_init_with_capacity(allocator, buffer, RBS_BUFFER_DEFAULT_CAPACITY);
12+
}
13+
14+
bool rbs_buffer_init_with_capacity(rbs_allocator_t *allocator, rbs_buffer_t *buffer, size_t capacity) {
1115
*buffer = (rbs_buffer_t) {
1216
.length = 0,
13-
.capacity = RBS_BUFFER_DEFAULT_CAPACITY,
14-
.value = rbs_allocator_calloc(allocator, RBS_BUFFER_DEFAULT_CAPACITY, char),
17+
.capacity = capacity,
18+
.value = rbs_allocator_calloc(allocator, capacity, char),
1519
};
1620

1721
return buffer->value != NULL;

0 commit comments

Comments
 (0)