| 27 | /* multiple add */ |
| 28 | |
| 29 | int |
| 30 | cirbuf_add_buf_head(struct cirbuf *cbuf, const char *c, unsigned int n) |
| 31 | { |
| 32 | unsigned int e; |
| 33 | |
| 34 | if (!cbuf || !c || !n || n > CIRBUF_GET_FREELEN(cbuf)) |
| 35 | return -EINVAL; |
| 36 | |
| 37 | e = CIRBUF_IS_EMPTY(cbuf) ? 1 : 0; |
| 38 | |
| 39 | if (n < cbuf->start + e) { |
| 40 | dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->start - n + e, n); |
| 41 | memcpy(cbuf->buf + cbuf->start - n + e, c, n); |
| 42 | } |
| 43 | else { |
| 44 | dprintf("s[%d] -> d[%d] (%d)\n", + n - (cbuf->start + e), 0, |
| 45 | cbuf->start + e); |
| 46 | dprintf("s[%d] -> d[%d] (%d)\n", cbuf->maxlen - n + |
| 47 | (cbuf->start + e), 0, n - (cbuf->start + e)); |
| 48 | memcpy(cbuf->buf, c + n - (cbuf->start + e) , cbuf->start + e); |
| 49 | memcpy(cbuf->buf + cbuf->maxlen - n + (cbuf->start + e), c, |
| 50 | n - (cbuf->start + e)); |
| 51 | } |
| 52 | cbuf->len += n; |
| 53 | cbuf->start += (cbuf->maxlen - n + e); |
| 54 | cbuf->start %= cbuf->maxlen; |
| 55 | return n; |
| 56 | } |
| 57 | |
| 58 | /* multiple add */ |
| 59 | |