aboutsummaryrefslogtreecommitdiff
path: root/src/types
diff options
context:
space:
mode:
authorame <[email protected]>2024-03-07 15:55:26 -0600
committerame <[email protected]>2024-03-07 15:55:26 -0600
commit580c39bb8d128b4f66d1c5d87a98ab7fb44a686b (patch)
tree55773fdf4ad75294ac3cf34a7fa08279c037ca3e /src/types
parent773e14c47bd91791c35f8715ad7e72b0b25105f0 (diff)
fixing stuff
Diffstat (limited to 'src/types')
-rw-r--r--src/types/str.c9
-rw-r--r--src/types/str.h1
2 files changed, 8 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);
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*);