cstr_copy

This commit is contained in:
Timerix 2025-11-13 06:16:57 +05:00
parent af36bab444
commit adaf5cc311
2 changed files with 12 additions and 0 deletions

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include "../std.h" #include "../std.h"
char* cstr_copy(cstr self);
#define strcat_malloc(STR0, ...) _strcat_malloc(count_args(__VA_ARGS__), STR0, __VA_ARGS__) #define strcat_malloc(STR0, ...) _strcat_malloc(count_args(__VA_ARGS__), STR0, __VA_ARGS__)
char* _strcat_malloc(u64 n, cstr str0, ...); char* _strcat_malloc(u64 n, cstr str0, ...);
char* _vstrcat_malloc(u64 n, cstr str0, va_list args); char* _vstrcat_malloc(u64 n, cstr str0, va_list args);

View File

@ -1,5 +1,15 @@
#include "tlibc/string/cstr.h" #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, ...){ char* _strcat_malloc(u64 n, cstr str0, ...){
va_list args; va_list args;
va_start(args, str0); va_start(args, str0);