65 buffer = (
char*) calloc(1, size);
150 size_t write_pos = 0;
152 char* new_buffer = NULL;
192 size_t buffer_size = 0;
195 size_t write_pos = 0;
196 char* new_buffer = NULL;
202 if(size == buffer_size) {
211 size_t move = (size > bytes) ? bytes : size;
227 if(move > new_size) {
237 new_buffer = (
char*) realloc(rb->
buffer_start, new_size);
264 if(count > data_size) {
266 memcpy(buf, rb->
read_pos, data_size);
269 memcpy(buf + data_size,
271 count > max_size ? max_size : count);
272 retval = data_size + (count > max_size ? max_size : count);
274 (count > max_size ? max_size : count);
277 memcpy(buf, rb->
read_pos, data_size > count ? count : data_size);
278 rb->
read_pos += data_size > count ? count : data_size;
279 retval = data_size > count ? count : data_size;
283 memcpy(buf, rb->
read_pos, data_size > count ? count : data_size);
284 rb->
read_pos += data_size > count ? count : data_size;
285 retval = data_size > count ? count : data_size;
293 const char*
const buf,
294 const size_t count) {
296 size_t free_space = 0;
301 if(free_space < count) {
308 if(count > free_space) {
310 memcpy(rb->
buffer_start, buf + free_space, count - free_space);
#define when_failed(x, l)
static char * amxc_rbuffer_alloc(amxc_rbuffer_t *const rb, const size_t size)
Ambiorix ring buffer API header file.
size_t amxc_rbuffer_size(const amxc_rbuffer_t *const rb)
Get the size of the data stored in the ring buffer.
int amxc_rbuffer_shrink(amxc_rbuffer_t *const rb, const size_t size)
Shrinks the ring buffer.
void amxc_rbuffer_clean(amxc_rbuffer_t *const rb)
Frees the buffer and sets all pointers of the ring buffer structure to NULL.
ssize_t amxc_rbuffer_write(amxc_rbuffer_t *const rb, const char *const buf, const size_t count)
Writes a number of bytes to the ring buffer.
int amxc_rbuffer_new(amxc_rbuffer_t **rb, const size_t size)
Allocates a ring buffer.
int amxc_rbuffer_grow(amxc_rbuffer_t *const rb, const size_t size)
Grows the ring buffer.
void amxc_rbuffer_delete(amxc_rbuffer_t **rb)
Frees the previously allocated ring buffer.
int amxc_rbuffer_init(amxc_rbuffer_t *const rb, const size_t size)
Initializes a ring buffer.
ssize_t amxc_rbuffer_read(amxc_rbuffer_t *const rb, char *const buf, size_t count)
Reads a number of bytes from the ring buffer.
The ring buffer structure.