gdkprivate: Add compatibility shim for g_set_str()
authorChristopher Davis <christopherdavis@gnome.org>
Fri, 16 Dec 2022 04:08:35 +0000 (23:08 -0500)
committerChristopher Davis <christopherdavis@gnome.org>
Fri, 16 Dec 2022 15:16:52 +0000 (10:16 -0500)
Allows us to make use of this API without depending
on bleeding-edge glib

gdk/gdkprivate.h

index 0f37cb0d8bbcfd4359f6001f85a9415c88a98cf3..95013947435656cc4f8a20b334e39addea751370 100644 (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__ */