libamxc  1.10.3
C Generic Data Containers
amxc_rbuffer.c File Reference

Ambiorix ring buffer API implementation. More...

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <amxc/amxc_rbuffer.h>
#include <amxc/amxc_macros.h>

Go to the source code of this file.

Functions

static char * amxc_rbuffer_alloc (amxc_rbuffer_t *const rb, const size_t size)
 
int amxc_rbuffer_new (amxc_rbuffer_t **rb, const size_t size)
 Allocates a ring buffer. More...
 
void amxc_rbuffer_delete (amxc_rbuffer_t **rb)
 Frees the previously allocated ring buffer. More...
 
int amxc_rbuffer_init (amxc_rbuffer_t *const rb, const size_t size)
 Initializes a ring buffer. More...
 
void amxc_rbuffer_clean (amxc_rbuffer_t *const rb)
 Frees the buffer and sets all pointers of the ring buffer structure to NULL. More...
 
int amxc_rbuffer_grow (amxc_rbuffer_t *const rb, const size_t size)
 Grows the ring buffer. More...
 
int amxc_rbuffer_shrink (amxc_rbuffer_t *const rb, const size_t size)
 Shrinks the ring buffer. More...
 
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. More...
 
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. More...
 
size_t amxc_rbuffer_size (const amxc_rbuffer_t *const rb)
 Get the size of the data stored in the ring buffer. More...
 

Detailed Description

Ambiorix ring buffer API implementation.

Definition in file amxc_rbuffer.c.

Function Documentation

◆ amxc_rbuffer_alloc()

static char* amxc_rbuffer_alloc ( amxc_rbuffer_t *const  rb,
const size_t  size 
)
static

Definition at line 62 of file amxc_rbuffer.c.

62  {
63  char* buffer = NULL;
64  if(rb->buffer_start == NULL) {
65  buffer = (char*) calloc(1, size);
66  } else {
67  buffer = (char*) realloc(rb->buffer_start, size);
68  }
69 
70  return buffer;
71 }
char * buffer_start
Definition: amxc_rbuffer.h:85