1 // SPDX-License-Identifier: GPL-2.0+
4 * Gerry Hamel, geh@ti.com, Texas Instruments
14 int buf_init (circbuf_t * buf, unsigned int size)
19 buf->totalsize = size;
20 buf->data = (char *) malloc (sizeof (char) * size);
21 assert (buf->data != NULL);
24 buf->tail = buf->data;
25 buf->end = &(buf->data[size]);
30 int buf_free (circbuf_t * buf)
33 assert (buf->data != NULL);
36 memset (buf, 0, sizeof (circbuf_t));
41 int buf_pop (circbuf_t * buf, char *dest, unsigned int len)
47 assert (dest != NULL);
51 /* Cap to number of bytes in buffer */
55 for (i = 0; i < len; i++) {
63 /* Update 'top' pointer */
70 int buf_push (circbuf_t * buf, const char *src, unsigned int len)
72 /* NOTE: this function allows push to overwrite old data. */
81 for (i = 0; i < len; i++) {
86 /* Make sure pushing too much data just replaces old data */
87 if (buf->size < buf->totalsize) {
91 if (buf->top == buf->end) {
97 /* Update 'tail' pointer */