/* colors.c
* Definitions for color structures and routines
*
- * $Id: colors.c,v 1.28 2000/01/03 06:59:07 guy Exp $
+ * $Id: colors.c,v 1.29 2000/01/29 16:41:13 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
#include "dfilter.h"
#include "simple_dialog.h"
#include "ui_util.h"
+#include "util.h"
extern capture_file cf;
return FALSE;
/* we have a clist */
- path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(fname) + 4);
- sprintf(path, "%s/%s", getenv("HOME"), fname);
+ path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(fname) + 4);
+ sprintf(path, "%s/%s", get_home_dir(), fname);
if ((f = fopen(path, "r")) == NULL) {
if (errno != ENOENT) {
gchar *path;
gchar *name = PF_DIR "/colorfilters";
/* decide what file to open (from dfilter code) */
- path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(name) + 4);
- sprintf(path, "%s/%s", getenv("HOME"), name);
+ path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(name) + 4);
+ sprintf(path, "%s/%s", get_home_dir(), name);
if ((f = fopen(path, "w+")) == NULL) {
simple_dialog(ESD_TYPE_WARN, NULL,
* (This used to be a notebook page under "Preferences", hence the
* "prefs" in the file name.)
*
- * $Id: filter_prefs.c,v 1.7 1999/12/10 07:20:57 guy Exp $
+ * $Id: filter_prefs.c,v 1.8 2000/01/29 16:41:27 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
#include "filter_prefs.h"
#include "packet.h"
#include "file.h"
+#include "util.h"
#include "prefs_dlg.h"
#define E_FILT_NAME_KEY "filter_name"
if (fl) return;
/* To do: generalize this */
- ff_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(ff_name) + 4);
- sprintf(ff_path, "%s/%s", getenv("HOME"), ff_name);
+ ff_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(ff_name) + 4);
+ sprintf(ff_path, "%s/%s", get_home_dir(), ff_name);
if ((ff = fopen(ff_path, "r")) == NULL) {
g_free(ff_path);
FILE *ff;
struct stat s_buf;
- ff_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(ff_dir) +
+ ff_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(ff_dir) +
strlen(ff_name) + 4);
- sprintf(ff_path, "%s/%s", getenv("HOME"), ff_dir);
+ sprintf(ff_path, "%s/%s", get_home_dir(), ff_dir);
if (stat(ff_path, &s_buf) != 0)
#ifdef WIN32
mkdir(ff_path, 0755);
#endif
- sprintf(ff_path, "%s/%s/%s", getenv("HOME"), ff_dir, ff_name);
+ sprintf(ff_path, "%s/%s/%s", get_home_dir(), ff_dir, ff_name);
if ((ff = fopen(ff_path, "w")) != NULL) {
flp = g_list_first(fl);
/* main.c
*
- * $Id: main.c,v 1.101 2000/01/29 13:30:08 gram Exp $
+ * $Id: main.c,v 1.102 2000/01/29 16:41:28 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
else if (cf.snap < MIN_PACKET_SIZE)
cf.snap = MIN_PACKET_SIZE;
- rc_file = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(RC_FILE) + 4);
- sprintf(rc_file, "%s/%s", getenv("HOME"), RC_FILE);
+ rc_file = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(RC_FILE) + 4);
+ sprintf(rc_file, "%s/%s", get_home_dir(), RC_FILE);
gtk_rc_parse(rc_file);
if ((m_r_font = gdk_font_load(medium_font)) == NULL) {
/* plugins.c
* plugin routines
*
- * $Id: plugins.c,v 1.5 2000/01/15 00:22:34 gram Exp $
+ * $Id: plugins.c,v 1.6 2000/01/29 16:41:14 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
#endif
#include "globals.h"
+#include "util.h"
/* linked list of all plugins */
plugin *pt_plug;
if (!plugin_status_file) {
- plugin_status_file = (gchar *)g_malloc(strlen(getenv("HOME")) + 26);
- sprintf(plugin_status_file, "%s/%s/plugins.status", getenv("HOME"), PF_DIR);
+ plugin_status_file = (gchar *)g_malloc(strlen(get_home_dir()) + 26);
+ sprintf(plugin_status_file, "%s/%s/plugins.status", get_home_dir(), PF_DIR);
}
statusfile=fopen(plugin_status_file, "w");
if (!statusfile) {
- pf_path = g_malloc(strlen(getenv("HOME")) + strlen(PF_DIR) + 2);
- sprintf(pf_path, "%s/%s", getenv("HOME"), PF_DIR);
+ pf_path = g_malloc(strlen(get_home_dir()) + strlen(PF_DIR) + 2);
+ sprintf(pf_path, "%s/%s", get_home_dir(), PF_DIR);
#ifdef WIN32
mkdir(pf_path);
#else
if (!plugin_status_file)
{
- plugin_status_file = (gchar *)g_malloc(strlen(getenv("HOME")) + 26);
- sprintf(plugin_status_file, "%s/%s/plugins.status", getenv("HOME"), PF_DIR);
+ plugin_status_file = (gchar *)g_malloc(strlen(get_home_dir()) + 26);
+ sprintf(plugin_status_file, "%s/%s/plugins.status", get_home_dir(), PF_DIR);
}
statusfile = fopen(plugin_status_file, "r");
}
if (!user_plug_dir)
{
- user_plug_dir = (gchar *)g_malloc(strlen(getenv("HOME")) + 19);
- sprintf(user_plug_dir, "%s/%s/plugins", getenv("HOME"), PF_DIR);
+ user_plug_dir = (gchar *)g_malloc(strlen(get_home_dir()) + 19);
+ sprintf(user_plug_dir, "%s/%s/plugins", get_home_dir(), PF_DIR);
}
plugins_scan_dir(user_plug_dir);
}
/* prefs.c
* Routines for handling preferences
*
- * $Id: prefs.c,v 1.29 2000/01/03 06:29:32 guy Exp $
+ * $Id: prefs.c,v 1.30 2000/01/29 16:41:14 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
#include "prefs.h"
#include "column.h"
#include "print.h"
+#include "util.h"
/* Internal functions */
static int set_pref(gchar*, gchar*);
}
if (! pf_path) {
- pf_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(PF_DIR) +
+ pf_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(PF_DIR) +
strlen(PF_NAME) + 4);
- sprintf(pf_path, "%s/%s/%s", getenv("HOME"), PF_DIR, PF_NAME);
+ sprintf(pf_path, "%s/%s/%s", get_home_dir(), PF_DIR, PF_NAME);
}
*pf_path_return = NULL;
*/
if (! pf_path) {
- pf_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(PF_DIR) +
+ pf_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(PF_DIR) +
strlen(PF_NAME) + 4);
}
- sprintf(pf_path, "%s/%s", getenv("HOME"), PF_DIR);
+ sprintf(pf_path, "%s/%s", get_home_dir(), PF_DIR);
if (stat(pf_path, &s_buf) != 0)
#ifdef WIN32
mkdir(pf_path);
mkdir(pf_path, 0755);
#endif
- sprintf(pf_path, "%s/%s/%s", getenv("HOME"), PF_DIR, PF_NAME);
+ sprintf(pf_path, "%s/%s/%s", get_home_dir(), PF_DIR, PF_NAME);
if ((pf = fopen(pf_path, "w")) == NULL) {
*pf_path_return = pf_path;
return errno;
/* resolv.c
* Routines for network object lookup
*
- * $Id: resolv.c,v 1.22 2000/01/10 17:32:52 gram Exp $
+ * $Id: resolv.c,v 1.23 2000/01/29 16:41:14 gram Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
#include "packet-ipx.h"
#include "globals.h"
#include "resolv.h"
+#include "util.h"
#define MAXMANUFLEN 9 /* max vendor name length with ending '\0' */
#define HASHETHSIZE 1024
* with it. It's used in get_ethbyname() and get_ethbyaddr()
*/
if (g_pethers_path == NULL) {
- g_pethers_path = g_malloc(strlen(getenv("HOME")) +
+ g_pethers_path = g_malloc(strlen(get_home_dir()) +
strlen(EPATH_PERSONAL_ETHERS) + 2);
sprintf(g_pethers_path, "%s/%s",
- (char *)getenv("HOME"), EPATH_PERSONAL_ETHERS);
+ get_home_dir(), EPATH_PERSONAL_ETHERS);
}
/* manuf hash table initialization */
* with it. It's used in get_ipxnetbyname() and get_ipxnetbyaddr()
*/
if (g_pipxnets_path == NULL) {
- g_pipxnets_path = g_malloc(strlen(getenv("HOME")) +
+ g_pipxnets_path = g_malloc(strlen(get_home_dir()) +
strlen(EPATH_PERSONAL_IPXNETS) + 2);
sprintf(g_pipxnets_path, "%s/%s",
- (char *)getenv("HOME"), EPATH_PERSONAL_IPXNETS);
+ get_home_dir(), EPATH_PERSONAL_IPXNETS);
}
} /* initialize_ipxnets */
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.30 2000/01/26 04:56:14 guy Exp $
+ * $Id: util.c,v 1.31 2000/01/29 16:41:15 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
}
}
+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";
+#endif
+
+ /* Return the cached value, if available */
+ if (home)
+ return home;
+
+ env_value = getenv("HOME");
+
+ if (env_value) {
+ home = env_value;
+ }
+ else {
+ home = default_home;
+ }
+
+ return home;
+}
+
+
+
#endif /* HAVE_LIBPCAP */
/* util.h
* Utility definitions
*
- * $Id: util.h,v 1.17 2000/01/25 05:48:39 guy Exp $
+ * $Id: util.h,v 1.18 2000/01/29 16:41:15 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
int create_tempfile(char *, int, const char *);
+/* Returns the user's home directory, via the HOME environment
+ * variable, or a default directory if HOME is not set */
+const char* get_home_dir(void);
+
void ASCII_to_EBCDIC(guint8 *buf, guint bytes);
guint8 ASCII_to_EBCDIC1(guint8 c);
void EBCDIC_to_ASCII(guint8 *buf, guint bytes);