m1n1/src/ringbuffer.h
Sven Peter ea362ea8f9 ringbuffer: add a simple ringbuffer data structure
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 18:39:33 +09:00

22 lines
491 B
C

#ifndef RINGBUFFER_H
#define RINGBUFFER_H
#include "types.h"
typedef struct {
u8 *buffer;
size_t len;
size_t read;
size_t write;
} ringbuffer_t;
ringbuffer_t *ringbuffer_alloc(size_t len);
void ringbuffer_free(ringbuffer_t *bfr);
size_t ringbuffer_read(u8 *target, size_t len, ringbuffer_t *bfr);
size_t ringbuffer_write(const u8 *src, size_t len, ringbuffer_t *bfr);
size_t ringbuffer_get_used(ringbuffer_t *bfr);
size_t ringbuffer_get_free(ringbuffer_t *bfr);
#endif