[glib] g_get_tmp_dir(): Clean up envars
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] g_get_tmp_dir(): Clean up envars
- Date: Sun, 4 Aug 2013 15:29:43 +0000 (UTC)
commit c2352409051df49a08d9dced5b69ede434e90723
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Jul 29 10:00:20 2013 -0400
g_get_tmp_dir(): Clean up envars
On UNIX, we should only ever be looking at TMPDIR.
On Windows, we should only ever look at TEMP.
Also, clean up the documentation to better describe what is actually
happening. The previous docs may have left someone confused about why
this function returns "/var/tmp" on Solaris, even with no TMPDIR set.
https://bugzilla.gnome.org/show_bug.cgi?id=705075
glib/gutils.c | 40 ++++++++++++++++++----------------------
1 files changed, 18 insertions(+), 22 deletions(-)
---
diff --git a/glib/gutils.c b/glib/gutils.c
index b0c51bf..0a9944f 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -954,12 +954,19 @@ g_get_home_dir (void)
/**
* g_get_tmp_dir:
*
- * Gets the directory to use for temporary files. This is found from
- * inspecting the environment variables <envar>TMPDIR</envar>,
- * <envar>TMP</envar>, and <envar>TEMP</envar> in that order. If none
- * of those are defined "/tmp" is returned on UNIX and "C:\" on Windows.
- * The encoding of the returned string is system-defined. On Windows,
- * it is always UTF-8. The return value is never %NULL or the empty string.
+ * Gets the directory to use for temporary files.
+ *
+ * On UNIX, this is taken from the <envar>TMPDIR</envar> environment
+ * variable. If the variable is not set, <literal>P_tmpdir</literal> is
+ * used, as defined by the system C library. Failing that, a hard-coded
+ * default of "/tmp" is returned.
+ *
+ * On Windows, the <envar>TEMP</envar> environment variable is used,
+ * with the root directory of the Windows installation (eg: "C:\") used
+ * as a default.
+ *
+ * The encoding of the returned string is system-defined. On Windows, it
+ * is always UTF-8. The return value is never %NULL or the empty string.
*
* Returns: the directory to use for temporary files.
*/
@@ -972,27 +979,16 @@ g_get_tmp_dir (void)
{
gchar *tmp;
- tmp = g_strdup (g_getenv ("TMPDIR"));
-
- if (tmp == NULL || *tmp == '\0')
- {
- g_free (tmp);
- tmp = g_strdup (g_getenv ("TMP"));
- }
-
- if (tmp == NULL || *tmp == '\0')
- {
- g_free (tmp);
- tmp = g_strdup (g_getenv ("TEMP"));
- }
-
#ifdef G_OS_WIN32
+ tmp = g_strdup (g_getenv ("TEMP"));
+
if (tmp == NULL || *tmp == '\0')
{
g_free (tmp);
tmp = get_windows_directory_root ();
}
-#else
+#else /* G_OS_WIN32 */
+ tmp = g_strdup (g_getenv ("TMPDIR"));
#ifdef P_tmpdir
if (tmp == NULL || *tmp == '\0')
@@ -1004,7 +1000,7 @@ g_get_tmp_dir (void)
if (k > 1 && G_IS_DIR_SEPARATOR (tmp[k - 1]))
tmp[k - 1] = '\0';
}
-#endif
+#endif /* P_tmpdir */
if (tmp == NULL || *tmp == '\0')
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]