1 /* 2 * Copyright 2004-2008, François Revol, <revol@free.fr>. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _RINGBUFF_H 6 #define _RINGBUFF_H 7 8 struct ring_buffer { 9 size_t size; 10 size_t current; /* index of next byte to read */ 11 size_t avail; /* number of bytes in */ 12 unsigned char data[0]; 13 }; 14 15 void rb_init(struct ring_buffer *rb, size_t size); 16 void rb_clear(struct ring_buffer *rb); 17 size_t rb_can_write(struct ring_buffer *rb); 18 size_t rb_can_read(struct ring_buffer *rb); 19 size_t rb_write(struct ring_buffer *rb, void *data, size_t len); 20 size_t rb_read(struct ring_buffer *rb, void *data, size_t len); 21 22 #endif 23