*
* $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
#include <epan/proto.h>
#include "disabled_protos.h"
+#include <wsutil/file_util.h>
#define GLOBAL_PROTOCOLS_FILE_NAME "disabled_protos"
#define PROTOCOLS_FILE_NAME "disabled_protos"
#define INIT_BUF_SIZE 128
+static void
+discard_existing_list (GList **flp)
+{
+ GList *fl_ent;
+ protocol_def *prot;
+
+ if (*flp != NULL) {
+ fl_ent = g_list_first(*flp);
+ while (fl_ent != NULL) {
+ prot = (protocol_def *) fl_ent->data;
+ g_free(prot->name);
+ g_free(prot);
+ fl_ent = fl_ent->next;
+ }
+ g_list_free(*flp);
+ *flp = NULL;
+ }
+}
+
/*
* Read in a list of disabled protocols.
*
/* Construct the pathname of the global disabled protocols file. */
gff_path = get_datafile_path(GLOBAL_PROTOCOLS_FILE_NAME);
+ /* If we already have a list of protocols, discard it. */
+ discard_existing_list (&global_disabled_protos);
+
/* Read the global disabled protocols file, if it exists. */
*gpath_return = NULL;
- if ((ff = fopen(gff_path, "r")) != NULL) {
+ if ((ff = ws_fopen(gff_path, "r")) != NULL) {
/* We succeeded in opening it; read it. */
err = read_disabled_protos_list_file(gff_path, ff,
&global_disabled_protos);
}
/* Construct the pathname of the user's disabled protocols file. */
- ff_path = get_persconffile_path(PROTOCOLS_FILE_NAME, FALSE);
+ ff_path = get_persconffile_path(PROTOCOLS_FILE_NAME, TRUE, FALSE);
+
+ /* If we already have a list of protocols, discard it. */
+ discard_existing_list (&disabled_protos);
/* Read the user's disabled protocols file, if it exists. */
*path_return = NULL;
- if ((ff = fopen(ff_path, "r")) != NULL) {
+ if ((ff = ws_fopen(ff_path, "r")) != NULL) {
/* We succeeded in opening it; read it. */
err = read_disabled_protos_list_file(ff_path, ff, &disabled_protos);
if (err != 0) {
read_disabled_protos_list_file(const char *ff_path, FILE *ff,
GList **flp)
{
- GList *fl_ent;
protocol_def *prot;
int c;
char *prot_name;
int prot_name_index;
int line = 1;
- /* If we already have a list of protocols, discard it. */
- if (*flp != NULL) {
- fl_ent = g_list_first(*flp);
- while (fl_ent != NULL) {
- prot = (protocol_def *) fl_ent->data;
- g_free(prot->name);
- g_free(prot);
- fl_ent = fl_ent->next;
- }
- g_list_free(*flp);
- *flp = NULL;
- }
/* Allocate the protocol name buffer. */
prot_name_len = INIT_BUF_SIZE;
- prot_name = g_malloc(prot_name_len + 1);
+ prot_name = (char *)g_malloc(prot_name_len + 1);
for (line = 1; ; line++) {
/* Lines in a disabled protocol file contain the "filter name" of
if (prot_name_index >= prot_name_len) {
/* protocol name buffer isn't long enough; double its length. */
prot_name_len *= 2;
- prot_name = g_realloc(prot_name, prot_name_len + 1);
+ prot_name = (char *)g_realloc(prot_name, prot_name_len + 1);
}
prot_name[prot_name_index] = c;
prot_name_index++;
if (prot_name_index >= prot_name_len) {
/* protocol name buffer isn't long enough; double its length. */
prot_name_len *= 2;
- prot_name = g_realloc(prot_name, prot_name_len + 1);
+ prot_name = (char *)g_realloc(prot_name, prot_name_len + 1);
}
prot_name[prot_name_index] = '\0';
save_disabled_protos_list(char **pref_path_return, int *errno_return)
{
gchar *ff_path, *ff_path_new;
- const gchar *ff_name;
FILE *ff;
gint i;
protocol_t *protocol;
*pref_path_return = NULL; /* assume no error */
- ff_name = PROTOCOLS_FILE_NAME;
-
- ff_path = get_persconffile_path(ff_name, TRUE);
+ ff_path = get_persconffile_path(PROTOCOLS_FILE_NAME, TRUE, TRUE);
/* 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 = g_strdup_printf("%s.new", ff_path);
- if ((ff = fopen(ff_path_new, "w")) == NULL) {
+ if ((ff = ws_fopen(ff_path_new, "w")) == NULL) {
*pref_path_return = ff_path;
*errno_return = errno;
g_free(ff_path_new);
if (fclose(ff) == EOF) {
*pref_path_return = ff_path;
*errno_return = errno;
- unlink(ff_path_new);
+ ws_unlink(ff_path_new);
g_free(ff_path_new);
return;
}
exists; the Win32 call to rename files doesn't do so, which I
infer is the reason why the MSVC++ "rename()" doesn't do so.
We must therefore remove the target file first, on Windows. */
- if (remove(ff_path) < 0 && errno != ENOENT) {
+ if (ws_remove(ff_path) < 0 && errno != ENOENT) {
/* It failed for some reason other than "it's not there"; if
it's not there, we don't need to remove it, so we just
drive on. */
*pref_path_return = ff_path;
*errno_return = errno;
- unlink(ff_path_new);
+ ws_unlink(ff_path_new);
g_free(ff_path_new);
return;
}
#endif
- if (rename(ff_path_new, ff_path) < 0) {
+ if (ws_rename(ff_path_new, ff_path) < 0) {
*pref_path_return = ff_path;
*errno_return = errno;
- unlink(ff_path_new);
+ ws_unlink(ff_path_new);
g_free(ff_path_new);
return;
}