From: Tor Lillqvist Date: Wed, 8 Jun 2005 20:03:12 +0000 (+0000) Subject: New helper function on Win32, returns the root of the drive (or possibly X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=b8d34f660970f882e89bb45c3f6d0a8e2631ff05;p=dana%2Fcg-glib.git New helper function on Win32, returns the root of the drive (or possibly 2005-06-08 Tor Lillqvist * glib/gutils.c (get_windows_directory_root): New helper function on Win32, returns the root of the drive (or possibly share) where the Windows directory is. (In the case of Terminal Server sessions the Windows directory is a per-user folder.) (g_get_any_init): Use get_windows_directory_root() as last resort for both temp directory and home directory. g_get_home_dir() now never returns NULL on Win32. Don't look at HOMEDRIVE and HOMEPATH. HOME, USERPROFILE, CSIDL_PROFILE and Windows directory drive root should be enough. --- diff --git a/ChangeLog b/ChangeLog index cc3eabb1..ccde0de0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-06-08 Tor Lillqvist + + * glib/gutils.c (get_windows_directory_root): New helper function + on Win32, returns the root of the drive (or possibly share) where + the Windows directory is. (In the case of Terminal Server sessions + the Windows directory is a per-user folder.) + (g_get_any_init): Use get_windows_directory_root() as last resort + for both temp directory and home directory. g_get_home_dir() now + never returns NULL on Win32. Don't look at HOMEDRIVE and + HOMEPATH. HOME, USERPROFILE, CSIDL_PROFILE and Windows directory + drive root should be enough. + 2005-06-08 Matthias Clasen * glib/glib.symbols: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index cc3eabb1..ccde0de0 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +2005-06-08 Tor Lillqvist + + * glib/gutils.c (get_windows_directory_root): New helper function + on Win32, returns the root of the drive (or possibly share) where + the Windows directory is. (In the case of Terminal Server sessions + the Windows directory is a per-user folder.) + (g_get_any_init): Use get_windows_directory_root() as last resort + for both temp directory and home directory. g_get_home_dir() now + never returns NULL on Win32. Don't look at HOMEDRIVE and + HOMEPATH. HOME, USERPROFILE, CSIDL_PROFILE and Windows directory + drive root should be enough. + 2005-06-08 Matthias Clasen * glib/glib.symbols: diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index cc3eabb1..ccde0de0 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,15 @@ +2005-06-08 Tor Lillqvist + + * glib/gutils.c (get_windows_directory_root): New helper function + on Win32, returns the root of the drive (or possibly share) where + the Windows directory is. (In the case of Terminal Server sessions + the Windows directory is a per-user folder.) + (g_get_any_init): Use get_windows_directory_root() as last resort + for both temp directory and home directory. g_get_home_dir() now + never returns NULL on Win32. Don't look at HOMEDRIVE and + HOMEPATH. HOME, USERPROFILE, CSIDL_PROFILE and Windows directory + drive root should be enough. + 2005-06-08 Matthias Clasen * glib/glib.symbols: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index cc3eabb1..ccde0de0 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +2005-06-08 Tor Lillqvist + + * glib/gutils.c (get_windows_directory_root): New helper function + on Win32, returns the root of the drive (or possibly share) where + the Windows directory is. (In the case of Terminal Server sessions + the Windows directory is a per-user folder.) + (g_get_any_init): Use get_windows_directory_root() as last resort + for both temp directory and home directory. g_get_home_dir() now + never returns NULL on Win32. Don't look at HOMEDRIVE and + HOMEPATH. HOME, USERPROFILE, CSIDL_PROFILE and Windows directory + drive root should be enough. + 2005-06-08 Matthias Clasen * glib/glib.symbols: diff --git a/glib/gutils.c b/glib/gutils.c index c0c76ad6..b0b27c3b 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1414,6 +1414,26 @@ get_special_folder (int csidl) return retval; } +static char * +get_windows_directory_root (void) +{ + char windowsdir[MAX_PATH]; + + if (GetWindowsDirectory (windowsdir, sizeof (windowsdir))) + { + /* Usually X:\Windows, but in terminal server environments + * might be an UNC path, AFAIK. + */ + char *p = (char *) g_path_skip_root (windowsdir); + if (G_IS_DIR_SEPARATOR (p[-1]) && p[-2] != ':') + p--; + *p = '\0'; + return g_strdup (windowsdir); + } + else + return g_strdup ("C:\\"); +} + #endif /* HOLDS: g_utils_global_lock */ @@ -1428,6 +1448,10 @@ g_get_any_init (void) if (!g_tmp_dir) g_tmp_dir = g_strdup (g_getenv ("TEMP")); +#ifdef G_OS_WIN32 + if (!g_tmp_dir) + g_tmp_dir = get_windows_directory_root (); +#else #ifdef P_tmpdir if (!g_tmp_dir) { @@ -1441,12 +1465,9 @@ g_get_any_init (void) if (!g_tmp_dir) { -#ifndef G_OS_WIN32 g_tmp_dir = g_strdup ("/tmp"); -#else /* G_OS_WIN32 */ - g_tmp_dir = g_strdup ("\\"); -#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 @@ -1486,17 +1507,7 @@ g_get_any_init (void) g_home_dir = get_special_folder (CSIDL_PROFILE); if (!g_home_dir) - { - /* At least at some time, HOMEDRIVE and HOMEPATH were used - * to point to the home directory, I think. But on Windows - * 2000 HOMEDRIVE seems to be equal to SYSTEMDRIVE, and - * HOMEPATH is its root "\"? - */ - if (g_getenv ("HOMEDRIVE") != NULL && g_getenv ("HOMEPATH") != NULL) - g_home_dir = g_strconcat (g_getenv ("HOMEDRIVE"), - g_getenv ("HOMEPATH"), - NULL); - } + g_home_dir = get_windows_directory_root (); #endif /* G_OS_WIN32 */ #ifdef HAVE_PWD_H