X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fcmdline_cirbuf.c;h=f8ef1f0cd8bcb3c1f479da4e30bfca5c52260448;hb=c60ed50ac1449a2b2bccc33598d1f68458a36fb1;hp=8cd5374463ce4182383d92a0d202b349f481690d;hpb=6f32a68393e01b4179592b9f48255179e8ad55f7;p=libcmdline.git diff --git a/src/lib/cmdline_cirbuf.c b/src/lib/cmdline_cirbuf.c index 8cd5374..f8ef1f0 100644 --- a/src/lib/cmdline_cirbuf.c +++ b/src/lib/cmdline_cirbuf.c @@ -31,7 +31,7 @@ #include "cmdline_cirbuf.h" -void +void cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned int maxlen) { cbuf->maxlen = maxlen; @@ -52,7 +52,7 @@ cirbuf_add_buf_head(struct cirbuf *cbuf, const char *c, unsigned int n) 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); @@ -80,7 +80,7 @@ cirbuf_add_buf_tail(struct cirbuf *cbuf, const char *c, unsigned int 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); @@ -99,7 +99,7 @@ cirbuf_add_buf_tail(struct cirbuf *cbuf, const char *c, unsigned int n) /* add at head */ -static inline void +static inline void __cirbuf_add_head(struct cirbuf * cbuf, char c) { if (!CIRBUF_IS_EMPTY(cbuf)) { @@ -110,11 +110,11 @@ __cirbuf_add_head(struct cirbuf * cbuf, char c) 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; @@ -123,12 +123,12 @@ cirbuf_add_head_safe(struct cirbuf * cbuf, char c) 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)) { @@ -139,11 +139,11 @@ __cirbuf_add_tail(struct cirbuf * cbuf, char c) 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; @@ -152,7 +152,7 @@ cirbuf_add_tail_safe(struct cirbuf * cbuf, char c) void cirbuf_add_tail(struct cirbuf * cbuf, char c) { - __cirbuf_add_tail(cbuf, c); + __cirbuf_add_tail(cbuf, c); } @@ -163,7 +163,7 @@ __cirbuf_shift_left(struct cirbuf *cbuf) char tmp = cbuf->buf[cbuf->start]; for (i=0 ; ilen ; 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; @@ -180,7 +180,7 @@ __cirbuf_shift_right(struct cirbuf *cbuf) char tmp = cbuf->buf[cbuf->end]; for (i=0 ; ilen ; 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; @@ -322,7 +322,7 @@ int 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; @@ -365,7 +365,7 @@ cirbuf_get_buf_tail(struct cirbuf *cbuf, char *c, unsigned int size) /* get head or get tail */ -char +char cirbuf_get_head(struct cirbuf * cbuf) { return cbuf->buf[cbuf->start]; @@ -373,7 +373,7 @@ cirbuf_get_head(struct cirbuf * cbuf) /* get head or get tail */ -char +char cirbuf_get_tail(struct cirbuf * cbuf) { return cbuf->buf[cbuf->end];