From 580c39bb8d128b4f66d1c5d87a98ab7fb44a686b Mon Sep 17 00:00:00 2001 From: ame Date: Thu, 7 Mar 2024 15:55:26 -0600 Subject: fixing stuff --- src/types/str.c | 9 +++++++-- src/types/str.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/types') 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); diff --git a/src/types/str.h b/src/types/str.h index 20383c8..1f50eab 100644 --- a/src/types/str.h +++ b/src/types/str.h @@ -11,6 +11,7 @@ typedef struct { char* c; } str; +str* str_initl(char*, size_t len); str* str_init(char*); void str_free(str*); void str_push(str*, char*); -- cgit v1.2.3