17 unsigned int shift = 3;
19 while ((al_sz = (1 << shift)) < sz)
22 char* new_s = realloc(s->
str, al_sz);
53 memcpy(s->
str, buf, sz);
62 if (!init_str || !*init_str)
65 size_t slen = strlen(init_str);
77 memset(s, 0,
sizeof(*s));
88 if (new_sz <= s->
len) {
111 memcpy(s->
str + s->
len, buf, sz);
126 return (memcmp(a->
str, b->
str, a->
len) == 0);
131 if (pos == s->
len && len == 0)
136 ssize_t old_tail = s->
len - pos;
137 if ((len >= 0) && (len > old_tail))
140 memmove(&s->
str[pos], &s->
str[pos + len], old_tail - len);
cstring * cstr_new(const char *init_str)
cstring * cstr_new_sz(size_t sz)
btc_bool cstr_resize(cstring *s, size_t new_sz)
cstring * cstr_new_buf(const void *buf, size_t sz)
btc_bool cstr_erase(cstring *s, size_t pos, ssize_t len)
static btc_bool cstr_alloc_min_sz(cstring *s, size_t sz)
void cstr_free(cstring *s, btc_bool free_buf)
btc_bool cstr_append_buf(cstring *s, const void *buf, size_t sz)
btc_bool cstr_equal(const cstring *a, const cstring *b)