[gtk+/portal] Better sandbox detection
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/portal] Better sandbox detection
- Date: Thu, 7 Jul 2016 03:31:02 +0000 (UTC)
commit e0ff42761608adc78ef3bbeec499790ccac86b90
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jul 6 23:23:09 2016 -0400
Better sandbox detection
Use g_build_filename, and cache the result.
gtk/gtkprivate.c | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkprivate.c b/gtk/gtkprivate.c
index 7f2a335..02448d7 100644
--- a/gtk/gtkprivate.c
+++ b/gtk/gtkprivate.c
@@ -271,19 +271,23 @@ _gtk_ensure_resources (void)
gboolean
gtk_should_use_portal (void)
{
- const char *use_portal;
- char *path;
+ static const char *use_portal = NULL;
- path = g_strdup_printf ("%s/flatpak-info", g_get_user_runtime_dir ());
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- use_portal = "1";
- else
+ if (G_UNLIKELY (use_portal == NULL))
{
- use_portal = g_getenv ("GTK_USE_PORTAL");
- if (!use_portal)
- use_portal = "";
+ char *path;
+
+ path = g_build_filename (g_get_user_runtime_dir (), "flatpak-info", NULL);
+ if (g_file_test (path, G_FILE_TEST_EXISTS))
+ use_portal = "1";
+ else
+ {
+ use_portal = g_getenv ("GTK_USE_PORTAL");
+ if (!use_portal)
+ use_portal = "";
+ }
+ g_free (path);
}
- g_free (path);
- return g_str_equal (use_portal, "1");
+ return use_portal[0] == '1';
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]