diff options
Diffstat (limited to 'src/types')
| -rw-r--r-- | src/types/str.c | 13 | ||||
| -rw-r--r-- | src/types/str.h | 5 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/types/str.c b/src/types/str.c index 0c8d63a..e1818a2 100644 --- a/src/types/str.c +++ b/src/types/str.c @@ -16,6 +16,19 @@ str* str_initl(const char* init, size_t len){ return s;
}
+str* str_initfl(const char* init, size_t len){
+
+ 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) * sizeof * init);
+ s->c[len] = '\0';
+ return s;
+}
+
str* str_init(const char* init){
return str_initl(init, strlen(init));
}
diff --git a/src/types/str.h b/src/types/str.h index 86490cc..e650542 100644 --- a/src/types/str.h +++ b/src/types/str.h @@ -12,6 +12,9 @@ typedef struct { } str; str* str_initl(const char*, size_t len); +//str_initfl has the 'correct' behaviour where it forces the len and doesnt read extra bytes +//plan to switch everything to str_initfl, when everything will work with it +str* str_initfl(const char*, size_t len); str* str_init(const char*); void str_free(str*); void str_push(str*, const char*); @@ -19,4 +22,4 @@ void str_pushl(str*, const char*, size_t); void str_clear(str*); void str_popf(str*, int); void str_popb(str*, int); -#endif //__STR_H
\ No newline at end of file +#endif //__STR_H |
