Add cfw_string_set_nocopy().
This commit is contained in:
parent
69adb323ad
commit
7ad3af0b3d
2 changed files with 22 additions and 3 deletions
24
src/string.c
24
src/string.c
|
@ -180,19 +180,37 @@ bool
|
|||
cfw_string_set(CFWString *str, const char *cstr)
|
||||
{
|
||||
char *copy;
|
||||
size_t len;
|
||||
|
||||
if ((copy = cfw_strdup(cstr)) == NULL)
|
||||
return false;
|
||||
if (str != NULL) {
|
||||
if ((copy = cfw_strdup(cstr)) == NULL)
|
||||
return false;
|
||||
|
||||
len = strlen(copy);
|
||||
} else {
|
||||
copy = NULL;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
if (str->data != NULL)
|
||||
free(str->data);
|
||||
|
||||
str->data = copy;
|
||||
str->len = strlen(copy);
|
||||
str->len = len;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
cfw_string_set_nocopy(CFWString *str, char *cstr, size_t len)
|
||||
{
|
||||
if (str->data != NULL)
|
||||
free(str->data);
|
||||
|
||||
str->data = cstr;
|
||||
str->len = len;
|
||||
}
|
||||
|
||||
bool
|
||||
cfw_string_append(CFWString *str, CFWString *append)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue