cstr_copy
This commit is contained in:
parent
af36bab444
commit
adaf5cc311
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user