If necessary, expand the bytebuffer_t internal buffer to accommodate the specified additional size.
Definition at line 72 of file bytebuffer.c.
73{
74 LWDEBUGF(2,
"Entered bytebuffer_makeroom with space need of %zu", size_to_add);
75 size_t current_write_size = (
s->writecursor -
s->buf_start);
76 size_t capacity =
s->capacity;
77 size_t required_size = current_write_size + size_to_add;
78
79 LWDEBUGF(2,
"capacity = %zu and required size = %zu", capacity, required_size);
80 while (capacity < required_size)
81 capacity *= 2;
82
83 if ( capacity >
s->capacity )
84 {
85 size_t current_read_size = (
s->readcursor -
s->buf_start);
86 LWDEBUGF(4,
"We need to realloc more memory. New capacity is %zu", capacity);
87 if (
s->buf_start ==
s->buf_static )
88 {
90 memcpy(
s->buf_start,
s->buf_static,
s->capacity);
91 }
92 else
93 {
95 }
96 s->capacity = capacity;
97 s->writecursor =
s->buf_start + current_write_size;
98 s->readcursor =
s->buf_start + current_read_size;
99 }
100 return;
101}
void * lwrealloc(void *mem, size_t size)
void * lwalloc(size_t size)
#define LWDEBUGF(level, msg,...)
References lwalloc(), LWDEBUGF, lwrealloc(), and s.
Referenced by bytebuffer_append_byte(), bytebuffer_append_bytebuffer(), bytebuffer_append_uvarint(), and bytebuffer_append_varint().