diff options
| author | Tyge Løvset <[email protected]> | 2022-04-27 14:20:54 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-27 15:09:45 +0200 |
| commit | 37e950b8a93172f5f07fedaca54c9b2894416b5a (patch) | |
| tree | 47a5c9526c0d94598f1576fcd70d38ec82b9e9f4 /include/stc/alt | |
| parent | 8f55ea9afb719728afdc09d055fdf86c446f19ba (diff) | |
| download | STC-modified-37e950b8a93172f5f07fedaca54c9b2894416b5a.tar.gz STC-modified-37e950b8a93172f5f07fedaca54c9b2894416b5a.zip | |
Added cstr_expand_uninitialized().
Diffstat (limited to 'include/stc/alt')
| -rw-r--r-- | include/stc/alt/cstr.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index f81736dc..b366cd35 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -137,6 +137,13 @@ STC_INLINE cstr cstr_with_size(const size_t len, const char fill) { return s;
}
+STC_INLINE char* cstr_expand_uninitialized(cstr *self, size_t n) {
+ size_t len = cstr_size(*self); char* d;
+ if (!(d = cstr_reserve(self, len + n))) return NULL;
+ _cstr_p(self)->size += n;
+ return d + len;
+}
+
STC_INLINE cstr* cstr_take(cstr* self, cstr s) {
if (self->str != s.str && _cstr_p(self)->cap)
c_free(_cstr_p(self));
@@ -189,10 +196,11 @@ const cstr cstr_null = {_cstr_nullrep.chr}; STC_DEF char*
cstr_reserve(cstr* self, const size_t cap) {
- cstr_priv* p = _cstr_p(self);
+ cstr_priv *p = _cstr_p(self);
const size_t oldcap = p->cap;
if (cap > oldcap) {
p = (cstr_priv*) c_realloc(((oldcap != 0) & (p != &_cstr_nullrep)) ? p : NULL, _cstr_opt_mem(cap));
+ if (!p) return NULL;
self->str = p->chr;
if (oldcap == 0) self->str[p->size = 0] = '\0';
p->cap = _cstr_opt_cap(cap);
|
