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

Function sbuf_put_bytes

freebsd/kern/subr_sbuf.c:435–469  ·  view source on GitHub ↗

* Append bytes to an sbuf. This is the core function for appending * to an sbuf and is the main place that deals with extending the * buffer and marking overflow. */

Source from the content-addressed store, hash-verified

433 * buffer and marking overflow.
434 */
435static void
436sbuf_put_bytes(struct sbuf *s, const char *buf, size_t len)
437{
438 size_t n;
439
440 assert_sbuf_integrity(s);
441 assert_sbuf_state(s, 0);
442
443 if (s->s_error != 0)
444 return;
445 while (len > 0) {
446 if (SBUF_FREESPACE(s) <= 0) {
447 /*
448 * If there is a drain, use it, otherwise extend the
449 * buffer.
450 */
451 if (s->s_drain_func != NULL)
452 (void)sbuf_drain(s);
453 else if (sbuf_extend(s, len > INT_MAX ? INT_MAX : len)
454 < 0)
455 s->s_error = ENOMEM;
456 if (s->s_error != 0)
457 return;
458 }
459 n = SBUF_FREESPACE(s);
460 if (len < n)
461 n = len;
462 memcpy(&s->s_buf[s->s_len], buf, n);
463 s->s_len += n;
464 if (SBUF_ISSECTION(s))
465 s->s_sect_len += n;
466 len -= n;
467 buf += n;
468 }
469}
470
471static void
472sbuf_put_byte(struct sbuf *s, char c)

Callers 3

sbuf_put_byteFunction · 0.85
sbuf_bcatFunction · 0.85
sbuf_catFunction · 0.85

Calls 3

sbuf_drainFunction · 0.85
sbuf_extendFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected