#include struct rb { char buf[8]; char head; char tail; }; static void rb_initialize(struct rb* _rb) { memset(_rb, 0, sizeof(_rb)); } int rb_put(struct rb* _rb, char element) { if (_rb->tail != _rb->head) { _rb->buf[_rb->tail] = element; _rb->tail++; if (_rb->tail == sizeof(_rb->buf)) { _rb->tail = 0; } return 1; } else { return 0; } } int rb_get(struct rb* _rb, char *element) { if (_rb->tail != _rb->head) { *element = _rb->buf[_rb->head]; _rb->head++; if (_rb->head == sizeof(_rb->buf)) { _rb->head = 0; } return 1; } else { return 0; } }