Don't put "get_home_dir()" inside #ifdef HAVE_LIBPCAP/#endif.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 29 Jan 2000 19:06:59 +0000 (19:06 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 29 Jan 2000 19:06:59 +0000 (19:06 +0000)
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

util.c

diff --git a/util.c b/util.c
index 429741db2f803f65e7cb223068ba039d5247d90f..c55290ec959c918473a9d92592041850171d028e 100644 (file)
--- 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>
 # 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 */