/* Add an element to the end of the ringbuffer. 
This helper function does not check the pre-requirements for adding, i.e. the caller has to ensure that ringbuffer_full() is false.  */
static void add_tail(ringbuffer_t *restrict rb, char c)
/* Add an element to the end of the ringbuffer. 
This helper function does not check the pre-requirements for adding, i.e. the caller has to ensure that ringbuffer_full() is false.  */
static void add_tail(ringbuffer_t *restrict rb, char c)
{
    unsigned pos = rb->start + rb->avail++;
    if (pos >= rb->size) {
        pos -= rb->size;
    }
    rb->buf[pos] = c;
}