diff options
-rw-r--r-- | epan/filesystem.c | 36 | ||||
-rw-r--r-- | epan/filesystem.h | 10 | ||||
-rw-r--r-- | filters.c | 18 | ||||
-rw-r--r-- | gtk/colors.c | 13 | ||||
-rw-r--r-- | gtk/filter_prefs.c | 17 | ||||
-rw-r--r-- | gtk/prefs_dlg.c | 22 | ||||
-rw-r--r-- | prefs.c | 23 |
7 files changed, 87 insertions, 52 deletions
diff --git a/epan/filesystem.c b/epan/filesystem.c index 244a88dfa4..60331ae077 100644 --- a/epan/filesystem.c +++ b/epan/filesystem.c @@ -1,7 +1,7 @@ /* filesystem.c * Filesystem utility routines * - * $Id: filesystem.c,v 1.10 2001/10/23 03:40:39 guy Exp $ + * $Id: filesystem.c,v 1.11 2001/10/23 05:00:59 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -386,3 +386,37 @@ get_persconffile_dir(void) #endif return pf_dir; } + +/* + * Create the directory that holds personal configuration files, if + * necessary. If we attempted to create it, and failed, return -1 and + * set "*pf_dir_path_return" to the pathname of the directory; otherwise, + * return 0. + */ +int +create_persconffile_dir(const char **pf_dir_path_return) +{ + const char *pf_dir_path; + struct stat s_buf; + int ret; + + pf_dir_path = get_persconffile_dir(); + if (stat(pf_dir_path, &s_buf) != 0) { +#ifdef WIN32 + ret = mkdir(pf_dir_path); +#else + ret = mkdir(pf_dir_path, 0755); +#endif + } else { + /* + * Something with that pathname exists; if it's not + * a directory, we'll get an error if we try to put + * something in it, so we don't fail here, we wait + * for that attempt fo fail. + */ + ret = 0; + } + if (ret == -1) + *pf_dir_path_return = pf_dir_path; + return ret; +} diff --git a/epan/filesystem.h b/epan/filesystem.h index a0956dbb69..cb4cfde27e 100644 --- a/epan/filesystem.h +++ b/epan/filesystem.h @@ -1,7 +1,7 @@ /* filesystem.h * Filesystem utility definitions * - * $Id: filesystem.h,v 1.7 2001/10/22 23:16:01 guy Exp $ + * $Id: filesystem.h,v 1.8 2001/10/23 05:00:59 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -76,4 +76,12 @@ const char *get_systemfile_dir(void); */ const char *get_persconffile_dir(void); +/* + * Create the directory that holds personal configuration files, if + * necessary. If we attempted to create it, and failed, return -1 and + * set "*pf_dir_path_return" to the pathname of the directory; otherwise, + * return 0. + */ +int create_persconffile_dir(const char **pf_dir_path_return); + #endif /* FILESYSTEM_H */ @@ -1,7 +1,7 @@ /* filters.c * Code for reading and writing the filters file. * - * $Id: filters.c,v 1.11 2001/10/22 22:59:23 guy Exp $ + * $Id: filters.c,v 1.12 2001/10/23 05:00:57 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -31,18 +31,10 @@ #include <ctype.h> #include <errno.h> -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif - #ifdef HAVE_UNISTD_H #include <unistd.h> #endif -#ifdef HAVE_DIRECT_H -#include <direct.h> /* to declare "mkdir()" on Windows */ -#endif - #include <glib.h> #include <filesystem.h> @@ -425,7 +417,6 @@ save_filter_list(filter_list_type_t list, char **pref_path_return, GList *flp; filter_def *filt; FILE *ff; - struct stat s_buf; guchar *p, c; *pref_path_return = NULL; /* assume no error */ @@ -448,13 +439,6 @@ save_filter_list(filter_list_type_t list, char **pref_path_return, } pf_dir_path = get_persconffile_dir(); - if (stat(pf_dir_path, &s_buf) != 0) -#ifdef WIN32 - mkdir(pf_dir_path); -#else - mkdir(pf_dir_path, 0755); -#endif - path_length = strlen(pf_dir_path) + strlen(ff_name) + 2; ff_path = (gchar *) g_malloc(path_length); sprintf(ff_path, "%s" G_DIR_SEPARATOR_S "%s", pf_dir_path, ff_name); diff --git a/gtk/colors.c b/gtk/colors.c index 4df4a807e9..ac29b6db79 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.12 2001/10/22 22:59:26 guy Exp $ + * $Id: colors.c,v 1.13 2001/10/23 05:01:02 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -39,6 +39,7 @@ #endif #include <epan/filesystem.h> + #include "gtk/main.h" #include "packet.h" #include "colors.h" @@ -287,9 +288,19 @@ write_filter(gpointer filter_arg, gpointer file_arg) gboolean write_filters(colfilter *filter) { + const gchar *pf_dir_path; const gchar *path; FILE *f; + /* Create the directory that holds personal configuration files, + if necessary. */ + if (create_persconffile_dir(&pf_dir_path) == -1) { + simple_dialog(ESD_TYPE_WARN, NULL, + "Can't create directory\n\"%s\"\nfor color files: %s.", + pf_dir_path, strerror(errno)); + return FALSE; + } + path = get_colorfilter_file_path(); if ((f = fopen(path, "w+")) == NULL) { simple_dialog(ESD_TYPE_CRIT, NULL, diff --git a/gtk/filter_prefs.c b/gtk/filter_prefs.c index 3f23d9103b..50f645035d 100644 --- a/gtk/filter_prefs.c +++ b/gtk/filter_prefs.c @@ -3,12 +3,11 @@ * (This used to be a notebook page under "Preferences", hence the * "prefs" in the file name.) * - * $Id: filter_prefs.c,v 1.30 2001/06/27 10:00:14 guy Exp $ + * $Id: filter_prefs.c,v 1.31 2001/10/23 05:01:02 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 @@ -33,7 +32,7 @@ #include <gtk/gtk.h> -#include <epan.h> +#include <epan/filesystem.h> #include "filters.h" #include "gtk/main.h" @@ -709,10 +708,20 @@ static void filter_dlg_save_cb(GtkWidget *save_bt, gpointer data) { filter_list_type_t list = *(filter_list_type_t *)data; + const char *pf_dir_path; char *f_path; int f_save_errno; char *filter_type; + /* Create the directory that holds personal configuration files, + if necessary. */ + if (create_persconffile_dir(&pf_dir_path) == -1) { + simple_dialog(ESD_TYPE_WARN, NULL, + "Can't create directory\n\"%s\"\nfor filter files: %s.", + pf_dir_path, strerror(errno)); + return; + } + save_filter_list(list, &f_path, &f_save_errno); if (f_path != NULL) { /* We had an error saving the filter. */ diff --git a/gtk/prefs_dlg.c b/gtk/prefs_dlg.c index 38c91f1f82..75d2e399fa 100644 --- a/gtk/prefs_dlg.c +++ b/gtk/prefs_dlg.c @@ -1,7 +1,7 @@ /* prefs_dlg.c * Routines for handling preferences * - * $Id: prefs_dlg.c,v 1.30 2001/10/22 22:59:26 guy Exp $ + * $Id: prefs_dlg.c,v 1.31 2001/10/23 05:01:02 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -45,6 +45,8 @@ #include <sys/stat.h> #endif +#include <epan/filesystem.h> + #include "main.h" #include "gtkglobals.h" #include "packet.h" @@ -654,12 +656,20 @@ prefs_main_save_cb(GtkWidget *save_bt, gpointer parent_w) gui_prefs_fetch(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY)); prefs_module_foreach(module_prefs_fetch, &must_redissect); - /* Write the preferencs out. */ - err = write_prefs(&pf_path); - if (err != 0) { + /* Create the directory that holds personal configuration files, if + necessary. */ + if (create_persconffile_dir(&pf_path) == -1) { simple_dialog(ESD_TYPE_WARN, NULL, - "Can't open preferences file\n\"%s\": %s.", pf_path, - strerror(err)); + "Can't create directory\n\"%s\"\nfor preferences file: %s.", pf_path, + strerror(errno)); + } else { + /* Write the preferencs out. */ + err = write_prefs(&pf_path); + if (err != 0) { + simple_dialog(ESD_TYPE_WARN, NULL, + "Can't open preferences file\n\"%s\": %s.", pf_path, + strerror(err)); + } } /* Now apply those preferences. @@ -1,7 +1,7 @@ /* prefs.c * Routines for handling preferences * - * $Id: prefs.c,v 1.66 2001/10/22 22:59:23 guy Exp $ + * $Id: prefs.c,v 1.67 2001/10/23 05:00:57 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -30,10 +30,6 @@ #include <sys/types.h> #endif -#ifdef HAVE_DIRECT_H -#include <direct.h> -#endif - #include <stdlib.h> #include <string.h> #include <ctype.h> @@ -43,10 +39,6 @@ #include <unistd.h> #endif -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif - #include <filesystem.h> #include "globals.h" #include "packet.h" @@ -1463,10 +1455,8 @@ write_module_prefs(gpointer data, gpointer user_data) int write_prefs(const char **pf_path_return) { - const char *pf_dir_path; const char *pf_path; FILE *pf; - struct stat s_buf; GList *clp, *col_l; fmt_data *cfmt; @@ -1476,17 +1466,6 @@ write_prefs(const char **pf_path_return) * so that duplication can be avoided with filter.c */ - /* - * Create the directory that holds personal configuration files. - */ - pf_dir_path = get_persconffile_dir(); - if (stat(pf_dir_path, &s_buf) != 0) -#ifdef WIN32 - mkdir(pf_dir_path); -#else - mkdir(pf_dir_path, 0755); -#endif - pf_path = get_preffile_path(); if ((pf = fopen(pf_path, "w")) == NULL) { *pf_path_return = pf_path; |