Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
win32: use GetTempPath for g_tmp_dir
Browse files Browse the repository at this point in the history
%TMPDIR%, %TMP%, %TEMP% and get_windows_directory_root() were
checked in that order. However, on both XP an 7 %TMPDIR% does
not exist. Also, this behavior does not correspond with GetTempPath()
which returns one of %TMP%, %TEMP%, %USERPROFILE% or the Windows
directory (not the same as get_windows_directory_root()!), checked
in that order.

So simply use GetTempPath() instead.
  • Loading branch information
dieterv committed Nov 15, 2012
1 parent 44f1d6d commit 8c7c45b
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions glib/gutils.c
Expand Up @@ -616,6 +616,15 @@ g_get_any_init_do (void)
{
gchar hostname[100];

#ifdef G_OS_WIN32
wchar_t buffer[MAX_PATH];

if (GetTempPathW (MAX_PATH, buffer))
{
g_free (g_tmp_dir);
g_tmp_dir = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL);
}
#else
g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));

if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
Expand Down Expand Up @@ -647,7 +656,7 @@ g_get_any_init_do (void)
g_free (g_tmp_dir);
g_tmp_dir = g_strdup ("/tmp");
}
#endif /* !G_OS_WIN32 */
#endif /* G_OS_WIN32 */

#ifdef G_OS_WIN32
/* We check $HOME first for Win32, though it is a last resort for Unix
Expand Down Expand Up @@ -959,10 +968,16 @@ 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.
* Gets the directory to use for temporary files.
*
* On UNIX platforms 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 Windows the environment variables <envar>TMP</envar>, <envar>TEMP</envar>,
* <envar>USERPROFILE </envar> and the Windows directory are inspected in
* that order.
*
* 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.
*
Expand Down

0 comments on commit 8c7c45b

Please sign in to comment.