aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2000-03-14 08:26:19 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2000-03-14 08:26:19 +0000
commitc2b2155a8474c7f88f68e2a5c44591a28fba8f0c (patch)
tree8356655aa9852afbd4bb1f06f229e6436606db14 /util.c
parent17ebc6e107a984f98d6f599633b940248c825a9c (diff)
On Windows, when getting the user's home directory, don't look at the
HOME environment variable; instead, look at HOMEDRIVE and HOMEPATH. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@1718 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'util.c')
-rw-r--r--util.c74
1 files changed, 56 insertions, 18 deletions
diff --git a/util.c b/util.c
index 8b94d3b1dd..d05cc4cd67 100644
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.37 2000/02/22 07:07:46 guy Exp $
+ * $Id: util.c,v 1.38 2000/03/14 08:26:19 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -651,38 +651,76 @@ free_interface_list(GList *if_list)
const char*
get_home_dir(void)
{
- char *env_value;
static const char *home = NULL;
-#ifndef WIN32
+#ifdef WIN32
+ char *homedrive, *homepath;
+ char *homestring;
+ char *lastsep;
+#else
struct passwd *pwd;
#endif
/* Return the cached value, if available */
if (home)
return home;
-
- env_value = getenv("HOME");
-
- if (env_value) {
- home = env_value;
- }
- else {
#ifdef WIN32
- /* XXX - on NT, get the user name and append it to
- "C:\winnt\profiles\"?
- What about Windows 9x? */
+ /*
+ * XXX - should we use USERPROFILE anywhere in this process?
+ * Is there a chance that it might be set but one or more of
+ * HOMEDRIVE or HOMEPATH isn't set?
+ */
+ homedrive = getenv("HOMEDRIVE");
+ if (homedrive != NULL) {
+ homepath = getenv("HOMEPATH");
+ if (homepath != NULL) {
+ /*
+ * This is cached, so we don't need to worry about
+ * allocating multiple ones of them.
+ */
+ homestring =
+ g_malloc(strlen(homedrive) + strlen(homepath) + 1);
+ strcpy(homestring, homedrive);
+ strcat(homestring, homepath);
+
+ /*
+ * Trim off any trailing slash or backslash.
+ */
+ lastsep = find_last_pathname_separator(homestring);
+ if (lastsep != NULL && *(lastsep + 1) == '\0') {
+ /*
+ * Last separator is the last character
+ * in the string. Nuke it.
+ */
+ *lastsep = '\0';
+ }
+ home = homestring;
+ } else
+ home = homedrive;
+ } else {
+ /*
+ * Try using "windir?
+ */
home = "C:";
+ }
#else
+ home = getenv("HOME");
+ if (home == NULL) {
+ /*
+ * Get their home directory from the password file.
+ * If we can't even find a password file entry for them,
+ * use "/tmp".
+ */
pwd = getpwuid(getuid());
if (pwd != NULL) {
- /* This is cached, so we don't need to worry
- about allocating multiple ones of them. */
+ /*
+ * This is cached, so we don't need to worry
+ * about allocating multiple ones of them.
+ */
home = g_strdup(pwd->pw_dir);
- }
- else
+ } else
home = "/tmp";
-#endif
}
+#endif
return home;
}