rendered paste bodytypedef struct{ void* data; /* pointer to buffer */ size_t size; /* size of buffer */ void* head; /* point at which data is added */ void* tail; /* point at which data is removed */} cbuf;void cbuf_init(cbuf* buf, void* data, size_t size){ buf->data = data; buf->size = size; buf->head = data; buf->tail = data;}void cbuf_add(cbuf* dst, const void* src, size_t src_size){ size_t dst_remaining = ((char*)dst->data - (char*)dst->head) + dst->size; if(dst_remaining > src_size) { /* copy src to buffer, head doesnt wrap */ memcpy(dst->head, src, src_size); dst->head = (char*)dst->head + src_size; } else { /* head wraps, perform 2 copies */ memcpy(dst->head, src, dst_remaining); dst->head = dst->data; if(((char*)dst->head + src_size - dst_remaining) > dst->tail) { printf("BUFFER FULL!!!!!!!\r\n"); } else { memcpy(dst->head, (char*)src + dst_remaining, src_size - dst_remaining); } }}