aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-10-21 21:48:00 +0000
committerGuy Harris <guy@alum.mit.edu>2001-10-21 21:48:00 +0000
commite980dd9d3bfe00047bc454a2a68d590c2deb37ea (patch)
tree63b6b1f2a27db0a1dcf8e986ed3441c7c3a0a274
parentfa928f62c3b9bf3bd69c6e83747f954d7ba1c7ea (diff)
Use G_DIR_SEPARATOR_S rather than "/" as a pathname separator in format
strings used to generate pathnames. Move the definition of PF_DIR from <epan/epan.h> to <epan/filesystem.h>, so that files requiring only the definition of PF_DIR don't have to include <epan/epan.h>, and get rid of no-longer-necessary includes of <epan/epan.h>. Add a routine to get the directory for "system files" such as "/etc/ethers" - it's "/etc" on UNIX, and the datafile directory on Windows (as there's no "/etc" on Windows). Use that to construct the pathname of the ethers and ipxnet files. svn path=/trunk/; revision=4056
-rw-r--r--epan/epan.h13
-rw-r--r--epan/filesystem.c22
-rw-r--r--epan/filesystem.h19
-rw-r--r--epan/plugins.c3
-rw-r--r--epan/resolv.c67
-rw-r--r--filters.c20
-rw-r--r--gtk/colors.c6
-rw-r--r--prefs.c14
8 files changed, 86 insertions, 78 deletions
diff --git a/epan/epan.h b/epan/epan.h
index a2d97585f8..a45387ffc5 100644
--- a/epan/epan.h
+++ b/epan/epan.h
@@ -1,6 +1,6 @@
/* epan.h
*
- * $Id: epan.h,v 1.6 2001/04/02 00:38:34 hagbard Exp $
+ * $Id: epan.h,v 1.7 2001/10/21 21:47:58 guy Exp $
*
* Ethereal Protocol Analyzer Library
*
@@ -56,15 +56,4 @@ epan_dissect_new(void* pseudo_header, const guint8* data, frame_data *fd, proto_
void
epan_dissect_free(epan_dissect_t* edt);
-
-
-
-
-/* Should this be ".libepan"? For backwards-compatibility, I'll keep
- * it ".ethereal" for now.
- */
-#define PF_DIR ".ethereal"
-
-
-
#endif /* EPAN_H */
diff --git a/epan/filesystem.c b/epan/filesystem.c
index 273cf8f164..ead507c535 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -1,7 +1,7 @@
/* filesystem.c
* Filesystem utility routines
*
- * $Id: filesystem.c,v 1.6 2001/08/21 08:16:54 guy Exp $
+ * $Id: filesystem.c,v 1.7 2001/10/21 21:47:58 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -191,8 +191,8 @@ test_for_directory(const char *path)
}
/*
- * Get the directory in which global configuration and data files are
- * stored.
+ * Get the directory in which Ethereal's global configuration and data
+ * files are stored.
*/
const char *
get_datafile_dir(void)
@@ -269,6 +269,22 @@ get_datafile_dir(void)
#endif
}
+/*
+ * Get the directory in which files that, at least on UNIX, are
+ * system files (such as "/etc/ethers") are stored; on Windows,
+ * there's no "/etc" directory, so we get them from the Ethereal
+ * global configuration and data file directory.
+ */
+const char *
+get_systemfile_dir(void)
+{
+#ifdef WIN32
+ return get_datafile_dir();
+#else
+ return "/etc";
+#endif
+}
+
/* Returns the user's home directory, via the HOME environment
* variable, or a default directory if HOME is not set */
const char*
diff --git a/epan/filesystem.h b/epan/filesystem.h
index d26fc929cf..37f4d432a8 100644
--- a/epan/filesystem.h
+++ b/epan/filesystem.h
@@ -1,7 +1,7 @@
/* filesystem.h
* Filesystem utility definitions
*
- * $Id: filesystem.h,v 1.4 2001/08/21 06:39:16 guy Exp $
+ * $Id: filesystem.h,v 1.5 2001/10/21 21:47:58 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -26,6 +26,15 @@
#define FILESYSTEM_H
/*
+ * Name of directory, under the user's home directory, in which
+ * personal configuration files are stored.
+ *
+ * XXX - should this be ".libepan"? For backwards-compatibility, I'll keep
+ * it ".ethereal" for now.
+ */
+#define PF_DIR ".ethereal"
+
+/*
* Given a pathname, return a pointer to the last pathname separator
* character in the pathname, or NULL if the pathname contains no
* separators.
@@ -63,6 +72,14 @@ int test_for_directory(const char *);
*/
const char *get_datafile_dir(void);
+/*
+ * Get the directory in which files that, at least on UNIX, are
+ * system files (such as "/etc/ethers") are stored; on Windows,
+ * there's no "/etc" directory, so we get them from the Ethereal
+ * global configuration and data file directory.
+ */
+const char *get_systemfile_dir(void);
+
/* 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);
diff --git a/epan/plugins.c b/epan/plugins.c
index 9594fdcf01..8ad868514c 100644
--- a/epan/plugins.c
+++ b/epan/plugins.c
@@ -1,7 +1,7 @@
/* plugins.c
* plugin routines
*
- * $Id: plugins.c,v 1.34 2001/09/14 09:27:35 guy Exp $
+ * $Id: plugins.c,v 1.35 2001/10/21 21:47:58 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -26,7 +26,6 @@
# include "config.h"
#endif
-#include <epan.h>
#include "plugins.h"
#ifdef HAVE_PLUGINS
diff --git a/epan/resolv.c b/epan/resolv.c
index b3d5f54bea..aa7457e077 100644
--- a/epan/resolv.c
+++ b/epan/resolv.c
@@ -1,7 +1,7 @@
/* resolv.c
* Routines for network object lookup
*
- * $Id: resolv.c,v 1.13 2001/10/21 19:54:49 guy Exp $
+ * $Id: resolv.c,v 1.14 2001/10/21 21:47:58 guy Exp $
*
* Laurent Deniel <deniel@worldnet.fr>
*
@@ -86,8 +86,6 @@
#define ENAME_ETHERS "ethers"
#define ENAME_IPXNETS "ipxnets"
#define ENAME_MANUF "manuf"
-#define EPATH_PERSONAL_ETHERS ".ethereal/ethers" /* with "$HOME/" prefix */
-#define EPATH_PERSONAL_IPXNETS ".ethereal/ipxnets" /* with "$HOME/" prefix */
#define MAXMANUFLEN 9 /* max vendor name length with ending '\0' */
#define HASHETHSIZE 1024
@@ -171,11 +169,11 @@ static int ipxnet_resolution_initialized = 0;
* GUI code to change them.
*/
-gchar *g_ethers_path = NULL; /* {directory}/ENAME_ETHERS */
-gchar *g_pethers_path = NULL; /* "$HOME"/EPATH_PERSONAL_ETHERS */
-gchar *g_ipxnets_path = NULL; /* {directory}/ENAME_IPXNETS */
-gchar *g_pipxnets_path = NULL; /* "$HOME"/EPATH_PERSONAL_IPXNETS */
- /* first resolving call */
+gchar *g_ethers_path = NULL; /* global ethers file */
+gchar *g_pethers_path = NULL; /* personal ethers file */
+gchar *g_ipxnets_path = NULL; /* global ipxnets file */
+gchar *g_pipxnets_path = NULL; /* personal ipxnets file */
+ /* first resolving call */
/*
* Local function definitions
@@ -410,7 +408,7 @@ static int fgetline(char **buf, int *size, FILE *fp)
* The following functions implement ethernet address resolution and
* ethers files parsing (see ethers(4)).
*
- * /etc/manuf has the same format as ethers(4) except that names are
+ * The manuf file has the same format as ethers(4) except that names are
* truncated to MAXMANUFLEN-1 characters and that an address contains
* only 3 bytes (instead of 6).
*
@@ -432,7 +430,7 @@ static int fgetline(char **buf, int *size, FILE *fp)
static int parse_ether_line(char *line, ether_t *eth, int six_bytes)
{
/*
- * See man ethers(4) for /etc/ethers file format
+ * See man ethers(4) for ethers file format
* (not available on all systems).
* We allow both ethernet address separators (':' and '-'),
* as well as Ethereal's '.' separator.
@@ -628,29 +626,22 @@ static void initialize_ethers(void)
ether_t *eth;
char *manuf_path;
- /* Compute the pathname of the ethers file.
- * On UNIX, it's "/etc/ethers"; on Windows, it's "ethers" under the
- * datafile directory (there's no notion of an "ethers file" on
- * Windows, so it's an Ethereal-specific file).
- */
+ /* Compute the pathname of the ethers file. */
if (g_ethers_path == NULL) {
-#ifdef WIN32
- dir = get_datafile_dir();
-#else
- dir = "/etc";
-#endif
- g_ethers_path = g_malloc(strlen(dir) + strlen(ENAME_ETHERS) + 2);
- sprintf(g_ethers_path, "%s/%s", dir, ENAME_ETHERS);
+ g_ethers_path = g_malloc(strlen(get_systemfile_dir()) +
+ strlen(ENAME_ETHERS) + 2);
+ sprintf(g_ethers_path, "%s" G_DIR_SEPARATOR_S "%s",
+ get_systemfile_dir(), ENAME_ETHERS);
}
/* Set g_pethers_path here, but don't actually do anything
* with it. It's used in get_ethbyname() and get_ethbyaddr()
*/
if (g_pethers_path == NULL) {
- g_pethers_path = g_malloc(strlen(get_home_dir()) +
- strlen(EPATH_PERSONAL_ETHERS) + 2);
- sprintf(g_pethers_path, "%s/%s",
- get_home_dir(), EPATH_PERSONAL_ETHERS);
+ g_pethers_path = g_malloc(strlen(get_home_dir()) +
+ strlen(PF_DIR) + strlen(ENAME_ETHERS) + 3);
+ sprintf(g_pethers_path, "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s",
+ get_home_dir(), PF_DIR, ENAME_ETHERS);
}
/* manuf hash table initialization */
@@ -658,7 +649,7 @@ static void initialize_ethers(void)
/* Compute the pathname of the manuf file */
manuf_path = (gchar *) g_malloc(strlen(get_datafile_dir()) +
strlen(ENAME_MANUF) + 2);
- sprintf(manuf_path, "%s%c%s", get_datafile_dir(), G_DIR_SEPARATOR,
+ sprintf(manuf_path, "%s" G_DIR_SEPARATOR_S "%s", get_datafile_dir(),
ENAME_MANUF);
/* Read it and initialize the hash table */
@@ -942,9 +933,6 @@ static void initialize_ipxnets(void)
char *dir;
/* Compute the pathname of the ipxnets file.
- * On UNIX, it's "/etc/ipxnets"; on Windows, it's "ipxnets" under the
- * datafile directory (there's no notion of an "ipxnets file" on
- * Windows, so it's an Ethereal-specific file).
*
* XXX - is there a notion of an "ipxnets file" in any flavor of
* UNIX, or with any add-on Netware package for UNIX? If not,
@@ -952,23 +940,20 @@ static void initialize_ipxnets(void)
* directory as well?
*/
if (g_ipxnets_path == NULL) {
-#ifdef WIN32
- dir = get_datafile_dir();
-#else
- dir = "/etc";
-#endif
- g_ipxnets_path = g_malloc(strlen(dir) + strlen(ENAME_IPXNETS) + 2);
- sprintf(g_ipxnets_path, "%s/%s", dir, ENAME_IPXNETS);
+ g_ipxnets_path = g_malloc(strlen(get_systemfile_dir()) +
+ strlen(ENAME_IPXNETS) + 2);
+ sprintf(g_ipxnets_path, "%s" G_DIR_SEPARATOR_S "%s",
+ get_systemfile_dir(), ENAME_IPXNETS);
}
/* Set g_pipxnets_path here, but don't actually do anything
* with it. It's used in get_ipxnetbyname() and get_ipxnetbyaddr()
*/
if (g_pipxnets_path == NULL) {
- g_pipxnets_path = g_malloc(strlen(get_home_dir()) +
- strlen(EPATH_PERSONAL_IPXNETS) + 2);
- sprintf(g_pipxnets_path, "%s/%s",
- get_home_dir(), EPATH_PERSONAL_IPXNETS);
+ g_pipxnets_path = g_malloc(strlen(get_home_dir()) +
+ strlen(PF_DIR) + strlen(ENAME_IPXNETS) + 3);
+ sprintf(g_pipxnets_path, "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s",
+ get_home_dir(), PF_DIR, ENAME_IPXNETS);
}
} /* initialize_ipxnets */
diff --git a/filters.c b/filters.c
index a82cf25a32..b6a10739da 100644
--- a/filters.c
+++ b/filters.c
@@ -1,12 +1,11 @@
/* filters.c
* Code for reading and writing the filters file.
*
- * $Id: filters.c,v 1.9 2001/04/02 09:53:42 guy Exp $
+ * $Id: filters.c,v 1.10 2001/10/21 21:47:57 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
- *
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -46,7 +45,6 @@
#include <glib.h>
-#include <epan.h>
#include <filesystem.h>
#include "filters.h"
@@ -124,7 +122,8 @@ read_filter_list(filter_list_type_t list, char **pref_path_return,
/* To do: generalize this */
ff_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(ff_dir) +
strlen(ff_name) + 4);
- sprintf(ff_path, "%s/%s/%s", get_home_dir(), ff_dir, ff_name);
+ sprintf(ff_path, "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s",
+ get_home_dir(), ff_dir, ff_name);
if ((ff = fopen(ff_path, "r")) == NULL) {
/*
@@ -147,7 +146,8 @@ read_filter_list(filter_list_type_t list, char **pref_path_return,
* the filter lists, and delete the ones that don't belong in
* a particular list.
*/
- sprintf(ff_path, "%s/%s/%s", get_home_dir(), ff_dir, FILTER_FILE_NAME);
+ sprintf(ff_path, "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s",
+ get_home_dir(), ff_dir, FILTER_FILE_NAME);
if ((ff = fopen(ff_path, "r")) == NULL) {
/*
* Well, that didn't work, either. Just give up.
@@ -449,7 +449,7 @@ save_filter_list(filter_list_type_t list, char **pref_path_return,
path_length = strlen(get_home_dir()) + strlen(ff_dir) + strlen(ff_name)
+ 4 + 4;
ff_path = (gchar *) g_malloc(path_length);
- sprintf(ff_path, "%s/%s", get_home_dir(), ff_dir);
+ sprintf(ff_path, "%s" G_DIR_SEPARATOR_S "%s", get_home_dir(), ff_dir);
if (stat(ff_path, &s_buf) != 0)
#ifdef WIN32
@@ -458,13 +458,15 @@ save_filter_list(filter_list_type_t list, char **pref_path_return,
mkdir(ff_path, 0755);
#endif
- sprintf(ff_path, "%s/%s/%s", get_home_dir(), ff_dir, ff_name);
+ sprintf(ff_path, "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s",
+ get_home_dir(), ff_dir, ff_name);
/* Write to "XXX.new", and rename if that succeeds.
That means we don't trash the file if we fail to write it out
completely. */
ff_path_new = (gchar *) g_malloc(path_length);
- sprintf(ff_path_new, "%s/%s/%s.new", get_home_dir(), ff_dir, ff_name);
+ sprintf(ff_path_new, "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s.new",
+ get_home_dir(), ff_dir, ff_name);
if ((ff = fopen(ff_path_new, "w")) == NULL) {
*pref_path_return = ff_path;
diff --git a/gtk/colors.c b/gtk/colors.c
index 0b9c04e47c..4103816be3 100644
--- a/gtk/colors.c
+++ b/gtk/colors.c
@@ -1,12 +1,11 @@
/* colors.c
* Definitions for color structures and routines
*
- * $Id: colors.c,v 1.9 2001/04/24 00:28:21 guy Exp $
+ * $Id: colors.c,v 1.10 2001/10/21 21:48:00 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
- *
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -39,7 +38,6 @@
#include <sys/types.h>
#endif
-#include <epan.h>
#include <epan/filesystem.h>
#include "gtk/main.h"
#include "packet.h"
diff --git a/prefs.c b/prefs.c
index e28aa5a676..6b927ce1bc 100644
--- a/prefs.c
+++ b/prefs.c
@@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
- * $Id: prefs.c,v 1.64 2001/10/21 17:30:50 guy Exp $
+ * $Id: prefs.c,v 1.65 2001/10/21 21:47:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -47,7 +47,6 @@
#include <sys/stat.h>
#endif
-#include <epan.h>
#include <filesystem.h>
#include "globals.h"
#include "packet.h"
@@ -737,7 +736,8 @@ read_prefs(int *gpf_errno_return, char **gpf_path_return,
if (! gpf_path) {
gpf_path = (gchar *) g_malloc(strlen(get_datafile_dir()) +
strlen(GPF_NAME) + 2);
- sprintf(gpf_path, "%s%c%s", get_datafile_dir(), G_DIR_SEPARATOR, GPF_NAME);
+ sprintf(gpf_path, "%s" G_DIR_SEPARATOR_S "%s",
+ get_datafile_dir(), GPF_NAME);
}
/* Read the global preferences file, if it exists. */
@@ -760,7 +760,8 @@ read_prefs(int *gpf_errno_return, char **gpf_path_return,
if (! pf_path) {
pf_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(PF_DIR) +
strlen(PF_NAME) + 4);
- sprintf(pf_path, "%s/%s/%s", get_home_dir(), PF_DIR, PF_NAME);
+ sprintf(pf_path, "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s",
+ get_home_dir(), PF_DIR, PF_NAME);
}
/* Read the user's preferences file, if it exists. */
@@ -1467,7 +1468,7 @@ write_prefs(char **pf_path_return)
strlen(PF_NAME) + 4);
}
- sprintf(pf_path, "%s/%s", get_home_dir(), PF_DIR);
+ sprintf(pf_path, "%s" G_DIR_SEPARATOR_S "%s", get_home_dir(), PF_DIR);
if (stat(pf_path, &s_buf) != 0)
#ifdef WIN32
mkdir(pf_path);
@@ -1475,7 +1476,8 @@ write_prefs(char **pf_path_return)
mkdir(pf_path, 0755);
#endif
- sprintf(pf_path, "%s/%s/%s", get_home_dir(), PF_DIR, PF_NAME);
+ sprintf(pf_path, "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s",
+ get_home_dir(), PF_DIR, PF_NAME);
if ((pf = fopen(pf_path, "w")) == NULL) {
*pf_path_return = pf_path;
return errno;