diff options
author | WormHeamer | 2025-02-05 18:57:19 -0500 |
---|---|---|
committer | WormHeamer | 2025-02-05 18:57:19 -0500 |
commit | 8c5cbf0a3c3eec140136ca5b81d491dab7d2d3c9 (patch) | |
tree | 547ed5e9b8140d4c6dcc9b860a4568d9ddf82dc9 /str.h | |
parent | 18901338effd8179c08a8b927fde231502328509 (diff) |
add stdwrm.h; fix scatc segfault; slen/sfree string not string*
Diffstat (limited to 'str.h')
-rw-r--r-- | str.h | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/str.h b/str.h index c0fc626..7959488 100644 --- a/str.h +++ b/str.h @@ -2,6 +2,8 @@ #define STR_H #include <string.h> + +#include "stdwrm.h" #include "dynarr.h" typedef DYNARR(char) string; @@ -14,10 +16,10 @@ typedef struct { #define strv(s) (strv_t) { s, strlen(s) } string snew(void); -size_t slen(const string *); +size_t slen(const string); void scats(string *, strv_t); void scatc(string *, char); -void sfree(string *); +void sfree(string); #ifdef STDWRM_STR_IMPL @@ -28,28 +30,28 @@ string snew(void) { return s; } -size_t slen(const string *s) { - return DA_LEN(*s) - 1; +size_t slen(const string s) { + return DA_LEN(s) - 1; } void scatc(string *s, char c) { size_t n = DA_LEN(*s) + 1; DA_FIT(*s, n); - *s[n-2] = c; - *s[n-1] = '\0'; + (*s)[n-2] = c; + (*s)[n-1] = '\0'; DA_LEN(*s) = n; } void scats(string *s, strv_t sv) { size_t n = DA_LEN(*s) + sv.n; DA_FIT(*s, n); - memcpy(&(*s)[slen(s)], sv.s, sv.n); + memcpy(&(*s)[slen(*s)], sv.s, sv.n); (*s)[n-1] = '\0'; DA_LEN(*s) = n; } -void sfree(string *s) { - DA_FREE(*s); +void sfree(string s) { + DA_FREE(s); } #endif |