]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - lib/circbuf.c
3 * Gerry Hamel, geh@ti.com, Texas Instruments
5 * SPDX-License-Identifier: GPL-2.0+
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
);
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. */
77 for (i
= 0; i
< len
; i
++) {
82 /* Make sure pushing too much data just replaces old data */
83 if (buf
->size
< buf
->totalsize
) {
87 if (buf
->top
== buf
->end
) {
93 /* Update 'tail' pointer */