diff options
| author | ame <[email protected]> | 2024-03-07 15:55:26 -0600 |
|---|---|---|
| committer | ame <[email protected]> | 2024-03-07 15:55:26 -0600 |
| commit | 580c39bb8d128b4f66d1c5d87a98ab7fb44a686b (patch) | |
| tree | 55773fdf4ad75294ac3cf34a7fa08279c037ca3e /src/types/str.c | |
| parent | 773e14c47bd91791c35f8715ad7e72b0b25105f0 (diff) | |
fixing stuff
Diffstat (limited to 'src/types/str.c')
| -rw-r--r-- | src/types/str.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/types/str.c b/src/types/str.c index bfedd87..929057e 100644 --- a/src/types/str.c +++ b/src/types/str.c @@ -1,24 +1,29 @@ #include "str.h" #include "../lua.h" +#include "../util.h" #define alloc_buffer 64 -str* str_init(char* init){ +str* str_initl(char* init, size_t len){ if(init == NULL){ char cc = '\0'; init = &cc; } - size_t len = strlen(init); str* s = malloc(sizeof * s); s->_bytes = len + 1 + alloc_buffer; s->c = malloc(s->_bytes); + if(s->c == NULL) p_fatal("failed to allocate string\n"); s->len = len ; memcpy(s->c, init, len + 1); return s; } +str* str_init(char* init){ + return str_initl(init, strlen(init)); +} + void str_free(str* s){ free(s->c); return free(s); |
