| 351 | } php_sb_t; |
| 352 | |
| 353 | static void php_sb_put(php_sb_t *sb, const char *s, size_t n) { |
| 354 | if (sb->oom) { |
| 355 | return; |
| 356 | } |
| 357 | if (sb->len + n + SKIP_ONE > sb->cap) { |
| 358 | size_t ncap = sb->cap ? sb->cap * PAIR_LEN : CBM_SZ_256; |
| 359 | while (ncap < sb->len + n + SKIP_ONE) { |
| 360 | ncap *= PAIR_LEN; |
| 361 | } |
| 362 | char *grown = (char *)cbm_arena_alloc(sb->a, ncap); |
| 363 | if (!grown) { |
| 364 | sb->oom = true; |
| 365 | return; |
| 366 | } |
| 367 | if (sb->len) { |
| 368 | memcpy(grown, sb->buf, sb->len); |
| 369 | } |
| 370 | sb->buf = grown; |
| 371 | sb->cap = ncap; |
| 372 | } |
| 373 | memcpy(sb->buf + sb->len, s, n); |
| 374 | sb->len += n; |
| 375 | sb->buf[sb->len] = '\0'; |
| 376 | } |
| 377 | |
| 378 | static void php_sb_puts(php_sb_t *sb, const char *s) { |
| 379 | php_sb_put(sb, s, strlen(s)); |
no test coverage detected