#include "cmdline_cirbuf.h"
-void
+void
cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned int maxlen)
{
cbuf->maxlen = maxlen;
return -EINVAL;
e = CIRBUF_IS_EMPTY(cbuf) ? 1 : 0;
-
+
if (n < cbuf->start + e) {
dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->start - n + e, n);
memcpy(cbuf->buf + cbuf->start - n + e, c, n);
return -EINVAL;
e = CIRBUF_IS_EMPTY(cbuf) ? 1 : 0;
-
+
if (n < cbuf->maxlen - cbuf->end - 1 + e) {
dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->end + !e, n);
memcpy(cbuf->buf + cbuf->end + !e, c, n);
/* add at head */
-static inline void
+static inline void
__cirbuf_add_head(struct cirbuf * cbuf, char c)
{
if (!CIRBUF_IS_EMPTY(cbuf)) {
cbuf->len ++;
}
-int
+int
cirbuf_add_head_safe(struct cirbuf * cbuf, char c)
{
if (cbuf && !CIRBUF_IS_FULL(cbuf)) {
- __cirbuf_add_head(cbuf, c);
+ __cirbuf_add_head(cbuf, c);
return 0;
}
return -EINVAL;
void
cirbuf_add_head(struct cirbuf * cbuf, char c)
{
- __cirbuf_add_head(cbuf, c);
+ __cirbuf_add_head(cbuf, c);
}
/* add at tail */
-static inline void
+static inline void
__cirbuf_add_tail(struct cirbuf * cbuf, char c)
{
if (!CIRBUF_IS_EMPTY(cbuf)) {
cbuf->len ++;
}
-int
+int
cirbuf_add_tail_safe(struct cirbuf * cbuf, char c)
{
if (cbuf && !CIRBUF_IS_FULL(cbuf)) {
- __cirbuf_add_tail(cbuf, c);
+ __cirbuf_add_tail(cbuf, c);
return 0;
}
return -EINVAL;
void
cirbuf_add_tail(struct cirbuf * cbuf, char c)
{
- __cirbuf_add_tail(cbuf, c);
+ __cirbuf_add_tail(cbuf, c);
}
char tmp = cbuf->buf[cbuf->start];
for (i=0 ; i<cbuf->len ; i++) {
- cbuf->buf[(cbuf->start+i)%cbuf->maxlen] =
+ cbuf->buf[(cbuf->start+i)%cbuf->maxlen] =
cbuf->buf[(cbuf->start+i+1)%cbuf->maxlen];
}
cbuf->buf[(cbuf->start-1+cbuf->maxlen)%cbuf->maxlen] = tmp;
char tmp = cbuf->buf[cbuf->end];
for (i=0 ; i<cbuf->len ; i++) {
- cbuf->buf[(cbuf->end+cbuf->maxlen-i)%cbuf->maxlen] =
+ cbuf->buf[(cbuf->end+cbuf->maxlen-i)%cbuf->maxlen] =
cbuf->buf[(cbuf->end+cbuf->maxlen-i-1)%cbuf->maxlen];
}
cbuf->buf[(cbuf->end+1)%cbuf->maxlen] = tmp;
cirbuf_get_buf_head(struct cirbuf *cbuf, char *c, unsigned int size)
{
unsigned int n = (size < CIRBUF_GET_LEN(cbuf)) ? size : CIRBUF_GET_LEN(cbuf);
-
+
if (!n)
return 0;
/* get head or get tail */
-char
+char
cirbuf_get_head(struct cirbuf * cbuf)
{
return cbuf->buf[cbuf->start];
/* get head or get tail */
-char
+char
cirbuf_get_tail(struct cirbuf * cbuf)
{
return cbuf->buf[cbuf->end];