Пример #1
0
bool lwan_strbuf_append_char(struct lwan_strbuf *s, const char c)
{
    if (UNLIKELY(!grow_buffer_if_needed(s, s->used + 2)))
        return false;

    s->value.buffer[s->used++] = c;
    s->value.buffer[s->used] = '\0';

    return true;
}
Пример #2
0
bool
strbuf_append_char(strbuf_t *s, const char c)
{
    if (UNLIKELY(!grow_buffer_if_needed(s, s->len.buffer + 2)))
        return false;

    *(s->value.buffer + s->len.buffer++) = c;
    *(s->value.buffer + s->len.buffer) = '\0';

    return true;
}
Пример #3
0
bool lwan_strbuf_set(struct lwan_strbuf *s1, const char *s2, size_t sz)
{
    if (!sz)
        sz = strlen(s2);

    if (UNLIKELY(!grow_buffer_if_needed(s1, sz + 1)))
        return false;

    memcpy(s1->value.buffer, s2, sz);
    s1->used = sz;
    s1->value.buffer[sz] = '\0';

    return true;
}
Пример #4
0
bool lwan_strbuf_append_str(struct lwan_strbuf *s1, const char *s2, size_t sz)
{
    if (!sz)
        sz = strlen(s2);

    if (UNLIKELY(!grow_buffer_if_needed(s1, s1->used + sz + 2)))
        return false;

    memcpy(s1->value.buffer + s1->used, s2, sz);
    s1->used += sz;
    s1->value.buffer[s1->used] = '\0';

    return true;
}
Пример #5
0
bool lwan_strbuf_init_with_size(struct lwan_strbuf *s, size_t size)
{
    if (UNLIKELY(!s))
        return false;

    memset(s, 0, sizeof(*s));

    if (UNLIKELY(!grow_buffer_if_needed(s, size)))
        return false;

    s->used = 0;
    s->value.buffer[0] = '\0';

    return true;
}
Пример #6
0
bool
strbuf_grow_to(strbuf_t *s, size_t new_size)
{
    return grow_buffer_if_needed(s, new_size + 1);
}
Пример #7
0
bool lwan_strbuf_grow_to(struct lwan_strbuf *s, size_t new_size)
{
    return grow_buffer_if_needed(s, new_size + 1);
}