buf.c with ringbuffer