aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/colors.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-10-22 22:59:26 +0000
committerGuy Harris <guy@alum.mit.edu>2001-10-22 22:59:26 +0000
commite4db9c4b6440c4f34c67f670b0517b7eed269063 (patch)
tree87e09fb73dc03de0fcca177a74a3366751309398 /gtk/colors.c
parentf4c0885cbd1a3b26286bab47bb9803e5f4d6184d (diff)
Add a routine to get the directory in which personal configuration files
reside. Use it, rather than concatenating the user's home directory and ".ethereal" in a number of files. Fix up some additional places to use G_DIR_SEPARATOR_S as the pathname separator. svn path=/trunk/; revision=4061
Diffstat (limited to 'gtk/colors.c')
-rw-r--r--gtk/colors.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/gtk/colors.c b/gtk/colors.c
index 409d117a1f..4df4a807e9 100644
--- a/gtk/colors.c
+++ b/gtk/colors.c
@@ -1,7 +1,7 @@
/* colors.c
* Definitions for color structures and routines
*
- * $Id: colors.c,v 1.11 2001/10/21 21:56:05 guy Exp $
+ * $Id: colors.c,v 1.12 2001/10/22 22:59:26 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -161,6 +161,24 @@ delete_color_filter(color_filter_t *colorf)
g_free(colorf);
}
+/*
+ * Get the pathname of the preferences file.
+ */
+static const char *
+get_colorfilter_file_path(void)
+{
+ static gchar *cf_path = NULL;
+ static const char fname[] = "colorfilters";
+
+ if (cf_path == NULL) {
+ cf_path = (gchar *) g_malloc(strlen(get_persconffile_dir()) +
+ sizeof fname + 1);
+ sprintf(cf_path, "%s" G_DIR_SEPARATOR_S "%s", get_persconffile_dir(),
+ fname);
+ }
+ return cf_path;
+}
+
static gboolean
read_filters(colfilter *filter)
{
@@ -172,9 +190,8 @@ read_filters(colfilter *filter)
GdkColor fg_color, bg_color;
color_filter_t *colorf;
int i;
+ const gchar *path;
FILE *f;
- gchar *path;
- gchar *fname = PF_DIR G_DIR_SEPARATOR_S "colorfilters";
dfilter_t *temp_dfilter;
/* decide what file to open (from dfilter code) */
@@ -185,19 +202,15 @@ read_filters(colfilter *filter)
return FALSE;
/* we have a clist */
- path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(fname) + 4);
- sprintf(path, "%s/%s", get_home_dir(), fname);
-
+ path = get_colorfilter_file_path();
if ((f = fopen(path, "r")) == NULL) {
if (errno != ENOENT) {
simple_dialog(ESD_TYPE_CRIT, NULL,
"Could not open filter file\n\"%s\": %s.", path,
strerror(errno));
}
- g_free(path);
return FALSE;
}
- g_free(path);
i = 0;
@@ -274,24 +287,19 @@ write_filter(gpointer filter_arg, gpointer file_arg)
gboolean
write_filters(colfilter *filter)
{
+ const gchar *path;
FILE *f;
- gchar *path;
- gchar *name = PF_DIR G_DIR_SEPARATOR_S "colorfilters";
- /* decide what file to open (from dfilter code) */
- path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(name) + 4);
- sprintf(path, "%s/%s", get_home_dir(), name);
+ path = get_colorfilter_file_path();
if ((f = fopen(path, "w+")) == NULL) {
simple_dialog(ESD_TYPE_CRIT, NULL,
"Could not open\n%s\nfor writing: %s.",
path, strerror(errno));
- g_free(path);
return FALSE;
}
fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Ethereal\n");
g_slist_foreach(filter_list, write_filter, f);
fclose(f);
- g_free(path);
return TRUE;
}