aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2000-01-29 19:06:59 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2000-01-29 19:06:59 +0000
commitf8889feb7b875ea11d8103b3ad487186a26fb2de (patch)
treedb3a5389da8e7e28d1f0e76b7ab930dfa15d2400 /util.c
parentc29d307005a8f9f7308974a063c1eabca6ab7afb (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. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@1580 f5534014-38df-0310-8fa8-9805f1628bb7
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 */