mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Guarantee that g_get_tmp_dir () doesn't return an empty string
If it does, g_file_open_tmp() would be in trouble. Pointed out by Morten Welinder in bug 627969.
This commit is contained in:
parent
8e16bf2fb6
commit
8803182f4a
@ -1525,17 +1525,17 @@ g_get_any_init_do (void)
|
|||||||
gchar hostname[100];
|
gchar hostname[100];
|
||||||
|
|
||||||
g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
|
g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
|
||||||
if (!g_tmp_dir)
|
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
|
||||||
g_tmp_dir = g_strdup (g_getenv ("TMP"));
|
g_tmp_dir = g_strdup (g_getenv ("TMP"));
|
||||||
if (!g_tmp_dir)
|
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
|
||||||
g_tmp_dir = g_strdup (g_getenv ("TEMP"));
|
g_tmp_dir = g_strdup (g_getenv ("TEMP"));
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
if (!g_tmp_dir)
|
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
|
||||||
g_tmp_dir = get_windows_directory_root ();
|
g_tmp_dir = get_windows_directory_root ();
|
||||||
#else
|
#else
|
||||||
#ifdef P_tmpdir
|
#ifdef P_tmpdir
|
||||||
if (!g_tmp_dir)
|
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
|
||||||
{
|
{
|
||||||
gsize k;
|
gsize k;
|
||||||
g_tmp_dir = g_strdup (P_tmpdir);
|
g_tmp_dir = g_strdup (P_tmpdir);
|
||||||
@ -1545,7 +1545,7 @@ g_get_any_init_do (void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!g_tmp_dir)
|
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
|
||||||
{
|
{
|
||||||
g_tmp_dir = g_strdup ("/tmp");
|
g_tmp_dir = g_strdup ("/tmp");
|
||||||
}
|
}
|
||||||
@ -1868,7 +1868,7 @@ g_get_home_dir (void)
|
|||||||
* <envar>TMP</envar>, and <envar>TEMP</envar> in that order. If none
|
* <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.
|
* of those are defined "/tmp" is returned on UNIX and "C:\" on Windows.
|
||||||
* The encoding of the returned string is system-defined. On Windows,
|
* The encoding of the returned string is system-defined. On Windows,
|
||||||
* it is always UTF-8. The return value is never %NULL.
|
* it is always UTF-8. The return value is never %NULL or the empty string.
|
||||||
*
|
*
|
||||||
* Returns: the directory to use for temporary files.
|
* Returns: the directory to use for temporary files.
|
||||||
*/
|
*/
|
||||||
|
@ -123,17 +123,31 @@ test_appname (void)
|
|||||||
g_assert_cmpstr (appname, ==, "appname");
|
g_assert_cmpstr (appname, ==, "appname");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_tmpdir (void)
|
||||||
|
{
|
||||||
|
g_test_bug ("627969");
|
||||||
|
g_assert_cmpstr (g_get_tmp_dir (), !=, "");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
{
|
{
|
||||||
argv0 = argv[0];
|
argv0 = argv[0];
|
||||||
|
|
||||||
|
/* for tmpdir test, need to do this early before g_get_any_init */
|
||||||
|
g_setenv ("TMPDIR", "", TRUE);
|
||||||
|
g_unsetenv ("TMP");
|
||||||
|
g_unsetenv ("TEMP");
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
g_test_bug_base ("http://bugzilla.gnome.org/");
|
||||||
|
|
||||||
g_test_add_func ("/utils/language-names", test_language_names);
|
g_test_add_func ("/utils/language-names", test_language_names);
|
||||||
g_test_add_func ("/utils/version", test_version);
|
g_test_add_func ("/utils/version", test_version);
|
||||||
g_test_add_func ("/utils/appname", test_appname);
|
g_test_add_func ("/utils/appname", test_appname);
|
||||||
|
g_test_add_func ("/utils/tmpdir", test_tmpdir);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user