#include #include #include #include bool ringbuffer_init(struct ringbuffer* rb, size_t capacity, size_t type_size) { void* buf = malloc(capacity * type_size); if (buf == NULL) return false; memset(rb, 0, sizeof(*rb)); rb->capacity = capacity; rb->buffer = buf; return true; } void ringbuffer_fini(struct ringbuffer* rb) { free(rb->buffer); }