string_copy adds trailing zero byte
This commit is contained in:
parent
dbf2c2772c
commit
5bbab0a414
@ -14,14 +14,16 @@ char* string_extract(string str){
|
||||
return cptr;
|
||||
}
|
||||
|
||||
// copies src.ptr content to new string
|
||||
// copies src.ptr content to new string and adds \0 at the end
|
||||
string string_copy(string src){
|
||||
if(!src.ptr) return src;
|
||||
if(!src.ptr)
|
||||
return src;
|
||||
string nstr;
|
||||
nstr.length=src.length;
|
||||
nstr.ptr=malloc(nstr.length);
|
||||
nstr.ptr=malloc(nstr.length+1);
|
||||
for(u32 i=0;i<nstr.length;i++)
|
||||
nstr.ptr[i]=src.ptr[i];
|
||||
nstr.ptr[nstr.length]='\0';
|
||||
return nstr;
|
||||
}
|
||||
|
||||
|
||||
@ -20,10 +20,13 @@ Autoarr_declare(string)
|
||||
|
||||
static const string stringNull={NULL,0};
|
||||
|
||||
/// wraps pointer without copy
|
||||
#define string_fromCptr(CPTR) (string){ .ptr=CPTR, .length=cptr_length(CPTR) }
|
||||
|
||||
// copies str content to new char pointer value (adding '\0' at the end)
|
||||
char* string_extract(string str);
|
||||
|
||||
// copies src.ptr content to new string
|
||||
// copies src.ptr content to new string and adds \0 at the end
|
||||
string string_copy(string src);
|
||||
|
||||
// compares two strings, NullPtr-friendly
|
||||
|
||||
Loading…
Reference in New Issue
Block a user