gdkprivate: Add compatibility shim for g_set_str()

Allows us to make use of this API without depending
on bleeding-edge glib
This commit is contained in:
Christopher Davis
2022-12-15 23:08:35 -05:00
parent 2442ed87fe
commit 3e86bc65f5

View File

@@ -23,4 +23,23 @@ void gdk_source_set_static_name_by_id (guint tag,
#define I_(string) g_intern_static_string (string)
#endif
#if !GLIB_CHECK_VERSION (2, 76, 0)
static inline gboolean
g_set_str (char **str_pointer,
const char *new_str)
{
char *copy;
if (*str_pointer == new_str ||
(*str_pointer && new_str && strcmp (*str_pointer, new_str) == 0))
return FALSE;
copy = g_strdup (new_str);
g_free (*str_pointer);
*str_pointer = copy;
return TRUE;
}
#endif
#endif /* __GDK__PRIVATE_H__ */