MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cirbuf_add_buf_head

Function cirbuf_add_buf_head

dpdk/lib/cmdline/cmdline_cirbuf.c:29–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27/* multiple add */
28
29int
30cirbuf_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

Calls 1

memcpyFunction · 0.50