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

Function cirbuf_add_buf_tail

dpdk/lib/cmdline/cmdline_cirbuf.c:60–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58/* multiple add */
59
60int
61cirbuf_add_buf_tail(struct cirbuf *cbuf, const char *c, unsigned int n)
62{
63 unsigned int e;
64
65 if (!cbuf || !c || !n || n > CIRBUF_GET_FREELEN(cbuf))
66 return -EINVAL;
67
68 e = CIRBUF_IS_EMPTY(cbuf) ? 1 : 0;
69
70 if (n < cbuf->maxlen - cbuf->end - 1 + e) {
71 dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->end + !e, n);
72 memcpy(cbuf->buf + cbuf->end + !e, c, n);
73 }
74 else {
75 dprintf("s[%d] -> d[%d] (%d)\n", cbuf->end + !e, 0,
76 cbuf->maxlen - cbuf->end - 1 + e);
77 dprintf("s[%d] -> d[%d] (%d)\n", cbuf->maxlen - cbuf->end - 1 +
78 e, 0, n - cbuf->maxlen + cbuf->end + 1 - e);
79 memcpy(cbuf->buf + cbuf->end + !e, c, cbuf->maxlen -
80 cbuf->end - 1 + e);
81 memcpy(cbuf->buf, c + cbuf->maxlen - cbuf->end - 1 + e,
82 n - cbuf->maxlen + cbuf->end + 1 - e);
83 }
84 cbuf->len += n;
85 cbuf->end += n - e;
86 cbuf->end %= cbuf->maxlen;
87 return n;
88}
89
90/* add at head */
91

Callers 10

rdline_char_inFunction · 0.85
rdline_add_historyFunction · 0.85
test_cirbuf_string_miscFunction · 0.85
test_cirbuf_align_leftFunction · 0.85
test_cirbuf_align_rightFunction · 0.85

Calls 1

memcpyFunction · 0.50