Add cfw_string_set_nocopy().

This commit is contained in:
Jonathan Schleifer 2012-09-30 01:22:12 +02:00
parent 69adb323ad
commit 7ad3af0b3d
2 changed files with 22 additions and 3 deletions

View file

@ -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)
{