| 77 | enum { CS_SB_INIT = 1024, CS_UINT_DIGITS = 16, CS_NAME_MAX = 512 }; |
| 78 | |
| 79 | static void sb_reserve(cs_sb_t *sb, size_t extra) { |
| 80 | if (sb->failed || sb->len + extra + SKIP_ONE <= sb->cap) { |
| 81 | return; |
| 82 | } |
| 83 | size_t ncap = sb->cap ? sb->cap : CS_SB_INIT; |
| 84 | while (ncap < sb->len + extra + SKIP_ONE) { |
| 85 | ncap *= PAIR_LEN; |
| 86 | } |
| 87 | char *grown = (char *)cbm_arena_alloc(sb->a, ncap); |
| 88 | if (!grown) { |
| 89 | sb->failed = true; |
| 90 | return; |
| 91 | } |
| 92 | if (sb->len > 0) { |
| 93 | memcpy(grown, sb->buf, sb->len); |
| 94 | } |
| 95 | sb->buf = grown; |
| 96 | sb->cap = ncap; |
| 97 | } |
| 98 | |
| 99 | static void sb_putn(cs_sb_t *sb, const char *s, size_t n) { |
| 100 | sb_reserve(sb, n); |
no test coverage detected