summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-21 13:10:18 +0200
committerTyge Løvset <[email protected]>2023-06-21 13:10:18 +0200
commite27a51708bf1ee4b22842b4a0924b3ded26f630c (patch)
tree0510bd099e25735f972ca8c9780f285efef9764d /include
parent08f75cf88252a3a95ee8eb8464295bcd177ec74f (diff)
downloadSTC-modified-e27a51708bf1ee4b22842b4a0924b3ded26f630c.tar.gz
STC-modified-e27a51708bf1ee4b22842b4a0924b3ded26f630c.zip
Update of cstr_append_uninit().
Diffstat (limited to 'include')
-rw-r--r--include/stc/algo/coroutine.h2
-rw-r--r--include/stc/cstr.h17
2 files changed, 10 insertions, 9 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index e0cf5488..e20fd8ad 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -101,7 +101,7 @@ typedef struct cco_base {
int cco_state;
} cco_base;
-#define cco_cast(closure) \
+#define cco_base_cast(closure) \
((cco_base *)(closure) + 0*sizeof((cco_resume(closure), (int*)0 == &(closure)->cco_state)))
#define cco_resume(closure) (closure)->cco_fn(closure)
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index b9b066ad..ce42cf8d 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -77,6 +77,7 @@ extern intptr_t cstr_find_at(const cstr* self, intptr_t pos, const char* sea
extern intptr_t cstr_find_sv(const cstr* self, csview search);
extern char* cstr_assign_n(cstr* self, const char* str, intptr_t len);
extern char* cstr_append_n(cstr* self, const char* str, intptr_t len);
+extern char* cstr_append_uninit(cstr *self, intptr_t len);
extern bool cstr_getdelim(cstr *self, int delim, FILE *fp);
extern void cstr_erase(cstr* self, intptr_t pos, intptr_t len);
extern void cstr_u8_erase(cstr* self, intptr_t bytepos, intptr_t u8len);
@@ -244,14 +245,6 @@ STC_INLINE cstr_iter cstr_advance(cstr_iter it, intptr_t pos) {
STC_INLINE void cstr_clear(cstr* self)
{ _cstr_set_size(self, 0); }
-STC_INLINE char* cstr_append_uninit(cstr *self, intptr_t len) {
- intptr_t sz = cstr_size(self);
- char* d = cstr_reserve(self, sz + len);
- if (!d) return NULL;
- _cstr_set_size(self, sz + len);
- return d + sz;
-}
-
STC_INLINE int cstr_cmp(const cstr* s1, const cstr* s2)
{ return strcmp(cstr_str(s1), cstr_str(s2)); }
@@ -551,6 +544,14 @@ char* cstr_append_n(cstr* self, const char* str, const intptr_t len) {
return r.data;
}
+char* cstr_append_uninit(cstr *self, intptr_t len) {
+ cstr_buf r = cstr_buffer(self);
+ if (r.size + len > r.cap && !(r.data = cstr_reserve(self, r.size*3/2 + len)))
+ return NULL;
+ _cstr_set_size(self, r.size + len);
+ return r.data + r.size;
+}
+
bool cstr_getdelim(cstr *self, const int delim, FILE *fp) {
int c = fgetc(fp);
if (c == EOF)