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

Function cirbuf_get_buf_head

dpdk/lib/cmdline/cmdline_cirbuf.c:323–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

321/* convert to buffer */
322
323int
324cirbuf_get_buf_head(struct cirbuf *cbuf, char *c, unsigned int size)
325{
326 unsigned int n;
327
328 if (!cbuf || !c)
329 return -EINVAL;
330
331 n = (size < CIRBUF_GET_LEN(cbuf)) ? size : CIRBUF_GET_LEN(cbuf);
332
333 if (!n)
334 return 0;
335
336 if (cbuf->start <= cbuf->end) {
337 dprintf("s[%d] -> d[%d] (%d)\n", cbuf->start, 0, n);
338 memcpy(c, cbuf->buf + cbuf->start , n);
339 }
340 else {
341 /* check if we need to go from end to the beginning */
342 if (n <= cbuf->maxlen - cbuf->start) {
343 dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->start, n);
344 memcpy(c, cbuf->buf + cbuf->start , n);
345 }
346 else {
347 dprintf("s[%d] -> d[%d] (%d)\n", cbuf->start, 0,
348 cbuf->maxlen - cbuf->start);
349 dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->maxlen - cbuf->start,
350 n - cbuf->maxlen + cbuf->start);
351 memcpy(c, cbuf->buf + cbuf->start , cbuf->maxlen - cbuf->start);
352 memcpy(c + cbuf->maxlen - cbuf->start, cbuf->buf,
353 n - cbuf->maxlen + cbuf->start);
354 }
355 }
356 return n;
357}
358
359/* convert to buffer */
360

Callers 9

rdline_char_inFunction · 0.85
test_cirbuf_string_miscFunction · 0.85
test_cirbuf_char_add_delFunction · 0.85
test_cirbuf_align_leftFunction · 0.85
test_cirbuf_align_rightFunction · 0.85

Calls 1

memcpyFunction · 0.50