aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-01-29 19:06:59 +0000
committerGuy Harris <guy@alum.mit.edu>2000-01-29 19:06:59 +0000
commitf292c583bfb68bf1db2f7463ba7f6304dabc5f07 (patch)
treedb3a5389da8e7e28d1f0e76b7ab930dfa15d2400 /util.c
parentea8136cd8e70da00e46ae281f14e089bd920919c (diff)
Don't put "get_home_dir()" inside #ifdef HAVE_LIBPCAP/#endif.
On UNIX, if "$HOME" isn't set, try getting the user ID and the password entry for that user ID, and, if that succeeds, get the home directory from the password entry, otherwise use "/tmp". On NT, it may be possible to do something similar (get the user name, and append that to "C:\winnt\profiles\"); I'm not sure whether there's anything that can be done on Windows 9x. svn path=/trunk/; revision=1580
Diffstat (limited to 'util.c')
-rw-r--r--util.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/util.c b/util.c
index 429741db2f..c55290ec95 100644
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.31 2000/01/29 16:41:15 gram Exp $
+ * $Id: util.c,v 1.32 2000/01/29 19:06:59 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -55,6 +55,10 @@
# include "snprintf.h"
#endif
+#ifndef WIN32
+#include <pwd.h>
+#endif
+
#ifdef NEED_MKSTEMP
#include "mkstemp.h"
#endif
@@ -574,15 +578,16 @@ free_interface_list(GList *if_list)
}
}
+#endif /* HAVE_LIBPCAP */
+
const char*
get_home_dir(void)
{
char *env_value;
static const char *home = NULL;
-#ifdef WIN32
- static const char *default_home = "C:";
-#else
- static const char *default_home = "/tmp";
+#ifndef
+ uid_t uid;
+ struct passwd *pwd;
#endif
/* Return the cached value, if available */
@@ -595,12 +600,23 @@ get_home_dir(void)
home = env_value;
}
else {
- home = default_home;
+#ifdef WIN32
+ /* XXX - on NT, get the user name and append it to
+ "C:\winnt\profiles\"?
+ What about Windows 9x? */
+ home = "C:"
+#else
+ uid = getuid();
+ pwd = getpwuid(uid);
+ if (pwd != NULL) {
+ /* This is cached, so we don't need to worry
+ about allocating multiple ones of them. */
+ home = g_strdup(pwd->pw_dir);
+ }
+ else
+ home = "/tmp";
+#endif
}
return home;
}
-
-
-
-#endif /* HAVE_LIBPCAP */