diff --git a/include/tlibc/string/cstr.h b/include/tlibc/string/cstr.h index 4712d39..d0081e4 100755 --- a/include/tlibc/string/cstr.h +++ b/include/tlibc/string/cstr.h @@ -1,6 +1,8 @@ #pragma once #include "../std.h" +char* cstr_copy(cstr self); + #define strcat_malloc(STR0, ...) _strcat_malloc(count_args(__VA_ARGS__), STR0, __VA_ARGS__) char* _strcat_malloc(u64 n, cstr str0, ...); char* _vstrcat_malloc(u64 n, cstr str0, va_list args); diff --git a/src/string/cstr.c b/src/string/cstr.c index b8425a3..9ab8dd2 100755 --- a/src/string/cstr.c +++ b/src/string/cstr.c @@ -1,5 +1,15 @@ #include "tlibc/string/cstr.h" +char* cstr_copy(cstr self){ + if(self == NULL) + return NULL; + + u64 len_with_zero = strlen(self) + 1; + char* copy = (char*)malloc(len_with_zero); + memcpy(copy, self, len_with_zero); + return copy; +} + char* _strcat_malloc(u64 n, cstr str0, ...){ va_list args; va_start(args, str0);