1 #ifndef FIFO_BUF_H 2 #define FIFO_BUF_H 3 4 #include <unistd.h> 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 struct fifo_buf 11 { 12 char *buf; /* The buffer content. */ 13 int size; /* Size of the buffer. */ 14 int pos; /* Current position. */ 15 int fill; /* Current fill. */ 16 }; 17 18 void fifo_buf_init (struct fifo_buf *b, const size_t size); 19 void fifo_buf_destroy (struct fifo_buf *b); 20 size_t fifo_buf_put (struct fifo_buf *b, const char *data, size_t size); 21 size_t fifo_buf_get (struct fifo_buf *b, char *user_buf, 22 size_t user_buf_size); 23 size_t fifo_buf_peek (struct fifo_buf *b, char *user_buf, 24 size_t user_buf_size); 25 size_t fifo_buf_get_space (const struct fifo_buf *b); 26 void fifo_buf_clear (struct fifo_buf *b); 27 size_t fifo_buf_get_fill (const struct fifo_buf *b); 28 size_t fifo_buf_get_size (const struct fifo_buf *b); 29 30 #ifdef __cplusplus 31 } 32 #endif 33 34 #endif 35