[glib] g_get_user_runtime_dir(): New function



commit ba9fccf71e667c1d05d05fab794ab41b2c387a81
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Nov 6 17:34:40 2010 -0400

    g_get_user_runtime_dir(): New function
    
    Get the value of the XDG_RUNTIME_DIR environment variable.

 docs/reference/glib/glib-sections.txt |    1 +
 glib/gutils.c                         |   49 +++++++++++++++++++++++++++++++++
 glib/gutils.h                         |    2 +
 3 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index dca0a98..1594bc8 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1607,6 +1607,7 @@ g_get_real_name
 g_get_user_cache_dir
 g_get_user_data_dir
 g_get_user_config_dir
+g_get_user_runtime_dir
 GUserDirectory
 g_get_user_special_dir
 g_get_system_data_dirs
diff --git a/glib/gutils.c b/glib/gutils.c
index 0227c8f..318eb34 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -2290,6 +2290,55 @@ g_get_user_cache_dir (void)
   return cache_dir;
 }
 
+/**
+ * g_get_user_runtime_dir:
+ *
+ * Returns a directory that is unique to the current user on the local
+ * system.
+ *
+ * On UNIX platforms this is determined using the mechanisms described in
+ * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec";>
+ * XDG Base Directory Specification</ulink>.  This is the directory
+ * specified in the XDG_RUNTIME_DIR environment variable.  In the case
+ * that this variable is not set, glib will issue a warning message to
+ * stderr and return the value of g_get_user_cache_dir().
+ *
+ * On Windows this is the folder to use for local (as opposed to
+ * roaming) application data. See documentation for
+ * CSIDL_LOCAL_APPDATA.  Note that on Windows it thus is the same as
+ * what g_get_user_config_dir() returns.
+ *
+ * Returns: a string owned by GLib that must not be modified or freed.
+ **/
+const gchar *
+g_get_user_runtime_dir (void)
+{
+#ifndef G_OS_WIN32
+  static const gchar *runtime_dir;
+  static gsize initialised;
+
+  if (g_once_init_enter (&initialised))
+    {
+      runtime_dir = g_strdup (getenv ("XDG_RUNTIME_DIR"));
+      
+      if (runtime_dir == NULL)
+        g_warning ("XDG_RUNTIME_DIR variable not set.  "
+                   "Falling back to XDG cache dir.");
+
+      g_once_init_leave (&initialised, 1);
+    }
+
+  if (runtime_dir)
+    return runtime_dir;
+
+  /* Both fallback for UNIX and the default
+   * in Windows: use the user cache directory.
+   */
+#endif
+
+  return g_get_user_cache_dir ();
+}
+
 #ifdef HAVE_CARBON
 
 static gchar *
diff --git a/glib/gutils.h b/glib/gutils.h
index 2809e90..e4d8277 100644
--- a/glib/gutils.h
+++ b/glib/gutils.h
@@ -153,6 +153,8 @@ _g_win32_get_system_data_dirs (void)
 
 G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_config_dirs (void);
 
+const gchar * g_get_user_runtime_dir (void);
+
 G_CONST_RETURN gchar* G_CONST_RETURN * g_get_language_names (void);
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]