1 // SPDX-License-Identifier: GPL-2.0+
12 int buf_init (circbuf_t * buf, unsigned int size)
17 buf->totalsize = size;
18 buf->data = (char *) malloc (sizeof (char) * size);
19 assert (buf->data != NULL);
22 buf->tail = buf->data;
23 buf->end = &(buf->data[size]);
28 int buf_free (circbuf_t * buf)
31 assert (buf->data != NULL);
34 memset (buf, 0, sizeof (circbuf_t));
39 int buf_pop (circbuf_t * buf, char *dest, unsigned int len)
45 assert (dest != NULL);
49 /* Cap to number of bytes in buffer */
53 for (i = 0; i < len; i++) {
61 /* Update 'top' pointer */
68 int buf_push (circbuf_t * buf, const char *src, unsigned int len)
70 /* NOTE: this function allows push to overwrite old data. */
79 for (i = 0; i < len; i++) {
84 /* Make sure pushing too much data just replaces old data */
85 if (buf->size < buf->totalsize) {
89 if (buf->top == buf->end) {
95 /* Update 'tail' pointer */