| 2476 | t->total += n; |
| 2477 | |
| 2478 | if (n >= t->cap) { |
| 2479 | memcpy(t->buf, s + n - t->cap, t->cap); |
| 2480 | t->start = 0; |
| 2481 | t->len = t->cap; |
| 2482 | return; |
| 2483 | } |
| 2484 | |
| 2485 | if (t->len < t->cap) { |
| 2486 | size_t free_tail = t->cap - t->len; |
| 2487 | size_t first = n < free_tail ? n : free_tail; |
| 2488 | size_t pos = (t->start + t->len) % t->cap; |
| 2489 | size_t right = t->cap - pos; |
| 2490 | size_t chunk = first < right ? first : right; |
| 2491 | memcpy(t->buf + pos, s, chunk); |
| 2492 | if (first > chunk) memcpy(t->buf, s + chunk, first - chunk); |
| 2493 | t->len += first; |
| 2494 | s += first; |
| 2495 | n -= first; |
| 2496 | } |
| 2497 |
no test coverage detected