* 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. */
| 433 | * buffer and marking overflow. |
| 434 | */ |
| 435 | static void |
| 436 | sbuf_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 | |
| 471 | static void |
| 472 | sbuf_put_byte(struct sbuf *s, char c) |
no test coverage detected