diff options
| author | rajdakin <rajdakin@gmail.com> | 2024-09-07 20:53:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-07 20:53:51 +0200 |
| commit | f30d75ae5dba339bfc95229894b22fd73e3fdc14 (patch) | |
| tree | 5cd75da181f43a7aaf29cab121069d9dba85aa2d /wrapperhelper/src/cstring.c | |
| parent | e087e7782ca9b2ce6c8ec99706a352b1c6ca12bc (diff) | |
| download | box64-f30d75ae5dba339bfc95229894b22fd73e3fdc14.tar.gz box64-f30d75ae5dba339bfc95229894b22fd73e3fdc14.zip | |
[WRAPPERHELPER] General improvements (#1804)
* [WRAPPERHELPER] Automatic headers detection, various bug fixes, added some cast support * [WRAPPERHELPER] Keep comments untouched
Diffstat (limited to 'wrapperhelper/src/cstring.c')
| -rw-r--r-- | wrapperhelper/src/cstring.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/wrapperhelper/src/cstring.c b/wrapperhelper/src/cstring.c index aecfb52e..86536915 100644 --- a/wrapperhelper/src/cstring.c +++ b/wrapperhelper/src/cstring.c @@ -71,6 +71,15 @@ int string_reserve_grow(string_t *s, size_t cap) { return 1; } +int string_trim(string_t *s) { + if (s->ssize == s->scap) return 1; + void *new_buf = realloc(s->buf, sizeof(char) * (s->ssize + 1)); + if (!new_buf) return 0; + s->buf = new_buf; + s->scap = s->ssize; + return 1; +} + void string_del(string_t *s) { if (s->buf) free(s->buf); free(s); @@ -118,6 +127,16 @@ void string_pop(string_t *s) { } } +void string_clear(string_t *s) { + if (!s->ssize) return; + if (!s->scap) return; + s->buf[s->ssize = 0] = '\0'; + void *new_buf = realloc(s->buf, sizeof(char)); + if (!new_buf) return; // We don't really care if the realloc fails, we just need to not update anything + s->buf = new_buf; + s->scap = 0; +} + string_t *string_dup(string_t const *s) { string_t *ret = string_new_cap(s->ssize); if (!ret) return NULL; |