Function
GLibset_str_take
unstable since: 2.90
Declaration [src]
static inline gboolean
g_set_str_take (
char** str_pointer,
char* new_str
)
Description [src]
Updates a pointer to a string to new_str and returns whether the
string was changed. Steals ownership of new_str.
If new_str matches the previous string, this function will free new_str and
leave str_pointer unchanged. If new_str is different, it will be assigned
to str_pointer and the previous string pointed to by str_pointer will be
freed with g_free().
str_pointer must not be NULL, but can point to a NULL value.
One convenient usage of this function is in implementing property settings:
void
foo_set_bar (Foo *foo,
const char *new_bar)
{
g_autofree computed_new_bar = NULL;
g_return_if_fail (IS_FOO (foo));
computed_new_bar = g_strconcat (new_bar, "some-suffix", NULL);
if (g_set_str_take (&foo->bar, g_steal_pointer (&computed_new_bar)))
g_object_notify (foo, "bar");
}
See also g_set_str() for a version of this which takes a copy of
new_str.
Available since: 2.90
This function is not directly available to language bindings.
Parameters
str_pointer-
Type:
char**A pointer to either a string or
NULL.The argument will be modified by the function. The caller of the function takes ownership of the returned data, and is responsible for freeing it. The value is a NUL terminated UTF-8 string. new_str-
Type:
char*A string to assign to
str_pointer.The argument can be NULL.The called function takes ownership of the data, and is responsible for freeing it. The value is a NUL terminated UTF-8 string.