"gtk_entry_get_text()" returns a "const char *" - assign the result to

one.

"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *". 

"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.

In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).

Clean up white space.

svn path=/trunk/; revision=12881
This commit is contained in:
Guy Harris 2004-12-31 00:26:36 +00:00
parent 6d24b27606
commit 6e622fd24e
14 changed files with 79 additions and 84 deletions

View File

@ -60,8 +60,8 @@
* character in the pathname, or NULL if the pathname contains no * character in the pathname, or NULL if the pathname contains no
* separators. * separators.
*/ */
char * static char *
find_last_pathname_separator(char *path) find_last_pathname_separator(const char *path)
{ {
char *separator; char *separator;
@ -72,7 +72,7 @@ find_last_pathname_separator(char *path)
* We have to scan for '\' or '/'. * We have to scan for '\' or '/'.
* Get to the end of the string. * Get to the end of the string.
*/ */
separator = path + strlen(path); /* points to ending '\0' */ separator = strchr(path, '\0'); /* points to ending '\0' */
while (separator > path) { while (separator > path) {
c = *--separator; c = *--separator;
if (c == '\\' || c == '/') if (c == '\\' || c == '/')
@ -93,10 +93,10 @@ find_last_pathname_separator(char *path)
/* /*
* Given a pathname, return the last component. * Given a pathname, return the last component.
*/ */
char * const char *
get_basename(char *path) get_basename(const char *path)
{ {
char *filename; const char *filename;
g_assert(path != NULL); g_assert(path != NULL);
filename = find_last_pathname_separator(path); filename = find_last_pathname_separator(path);

View File

@ -25,17 +25,10 @@
#ifndef FILESYSTEM_H #ifndef FILESYSTEM_H
#define FILESYSTEM_H #define FILESYSTEM_H
/*
* Given a pathname, return a pointer to the last pathname separator
* character in the pathname, or NULL if the pathname contains no
* separators.
*/
char *find_last_pathname_separator(char *);
/* /*
* Given a pathname, return the last component. * Given a pathname, return the last component.
*/ */
char *get_basename(char *); const char *get_basename(const char *);
/* /*
* Given a pathname, return a string containing everything but the * Given a pathname, return a string containing everything but the

54
file.c
View File

@ -301,14 +301,14 @@ cf_close(capture_file *cf)
static void static void
set_display_filename(capture_file *cf) set_display_filename(capture_file *cf)
{ {
gchar *name_ptr; const gchar *name_ptr;
size_t msg_len; size_t msg_len;
static const gchar done_fmt_nodrops[] = " File: %s %s %02u:%02u:%02u"; static const gchar done_fmt_nodrops[] = " File: %s %s %02u:%02u:%02u";
static const gchar done_fmt_drops[] = " File: %s %s %02u:%02u:%02u Drops: %u"; static const gchar done_fmt_drops[] = " File: %s %s %02u:%02u:%02u Drops: %u";
gchar *done_msg; gchar *done_msg;
gchar *win_name_fmt = "%s - Ethereal"; gchar *win_name_fmt = "%s - Ethereal";
gchar *win_name; gchar *win_name;
gchar *size_str; gchar *size_str;
name_ptr = cf_get_display_name(cf); name_ptr = cf_get_display_name(cf);
@ -345,28 +345,29 @@ set_display_filename(capture_file *cf)
read_status_t read_status_t
cf_read(capture_file *cf) cf_read(capture_file *cf)
{ {
int err; int err;
gchar *err_info; gchar *err_info;
gchar *name_ptr, *load_msg, *load_fmt = "%s"; const gchar *name_ptr;
char *errmsg; gchar *load_msg, *load_fmt = "%s";
char errmsg_errno[1024+1]; char *errmsg;
gchar err_str[2048+1]; char errmsg_errno[1024+1];
long data_offset; gchar err_str[2048+1];
progdlg_t *progbar = NULL; long data_offset;
gboolean stop_flag; progdlg_t *progbar = NULL;
gboolean stop_flag;
/* /*
* XXX - should be "off_t", but Wiretap would need more work to handle * XXX - should be "off_t", but Wiretap would need more work to handle
* the full size of "off_t" on platforms where it's more than a "long" * the full size of "off_t" on platforms where it's more than a "long"
* as well. * as well.
*/ */
long file_pos; long file_pos;
float prog_val; float prog_val;
int fd; int fd;
struct stat cf_stat; struct stat cf_stat;
GTimeVal start_time; GTimeVal start_time;
gchar status_str[100]; gchar status_str[100];
int progbar_nextstep; int progbar_nextstep;
int progbar_quantum; int progbar_quantum;
cum_bytes=0; cum_bytes=0;
reset_tap_listeners(); reset_tap_listeners();
@ -682,10 +683,10 @@ cf_finish_tail(capture_file *cf, int *err)
} }
#endif /* HAVE_LIBPCAP */ #endif /* HAVE_LIBPCAP */
gchar * const gchar *
cf_get_display_name(capture_file *cf) cf_get_display_name(capture_file *cf)
{ {
gchar *displayname; const gchar *displayname;
/* Return a name to use in displays */ /* Return a name to use in displays */
if (!cf->is_tempfile) { if (!cf->is_tempfile) {
@ -3042,7 +3043,8 @@ gboolean
cf_save(char *fname, capture_file *cf, packet_range_t *range, guint save_format) cf_save(char *fname, capture_file *cf, packet_range_t *range, guint save_format)
{ {
gchar *from_filename; gchar *from_filename;
gchar *name_ptr, *save_msg, *save_fmt = " Saving: %s..."; const gchar *name_ptr;
gchar *save_msg, *save_fmt = " Saving: %s...";
size_t msg_len; size_t msg_len;
int err; int err;
gboolean do_copy; gboolean do_copy;

2
file.h
View File

@ -51,7 +51,7 @@ read_status_t cf_continue_tail(capture_file *, int, int *);
read_status_t cf_finish_tail(capture_file *, int *); read_status_t cf_finish_tail(capture_file *, int *);
/* size_t read_frame_header(capture_file *); */ /* size_t read_frame_header(capture_file *); */
gboolean cf_save(char *fname, capture_file * cf, packet_range_t *range, guint save_format); gboolean cf_save(char *fname, capture_file * cf, packet_range_t *range, guint save_format);
gchar *cf_get_display_name(capture_file *); const gchar *cf_get_display_name(capture_file *);
gboolean gboolean
cf_merge_files(const char *out_filename, int out_fd, int in_file_count, cf_merge_files(const char *out_filename, int out_fd, int in_file_count,

View File

@ -204,11 +204,11 @@ static GtkWidget *
about_folders_page_new(void) about_folders_page_new(void)
{ {
GtkWidget *table; GtkWidget *table;
const char *path; const char *constpath;
char *path;
gchar *titles[] = { "Name", "Folder", "Typical Files"}; gchar *titles[] = { "Name", "Folder", "Typical Files"};
GtkWidget *scrolledwindow; GtkWidget *scrolledwindow;
scrolledwindow = scrolled_window_new(NULL, NULL); scrolledwindow = scrolled_window_new(NULL, NULL);
#if GTK_MAJOR_VERSION >= 2 #if GTK_MAJOR_VERSION >= 2
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow),
@ -235,20 +235,18 @@ about_folders_page_new(void)
g_free((void *) path); g_free((void *) path);
/* global conf */ /* global conf */
path = get_datafile_dir(); constpath = get_datafile_dir();
about_folders_row(table, "Global configuration", path, about_folders_row(table, "Global configuration", constpath,
"\"dfilters\", \"preferences\", \"manuf\", ..."); "\"dfilters\", \"preferences\", \"manuf\", ...");
/*g_free(path);*/
/* system */ /* system */
path = get_systemfile_dir(); constpath = get_systemfile_dir();
about_folders_row(table, "System", path, about_folders_row(table, "System", constpath,
"\"ethers\", \"ipxnets\""); "\"ethers\", \"ipxnets\"");
/*g_free(path);*/
/* program */ /* program */
path = g_strdup(ethereal_path); path = g_strdup(ethereal_path);
path = get_dirname((char *) path); path = get_dirname(path);
about_folders_row(table, "Program", path, about_folders_row(table, "Program", path,
"program files"); "program files");
g_free((void *) path); g_free((void *) path);

View File

@ -352,7 +352,7 @@ static void
dcerpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_) dcerpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{ {
GString *str; GString *str;
char *filter; const char *filter;
str = g_string_new("dcerpc,srt"); str = g_string_new("dcerpc,srt");
g_string_sprintfa(str, g_string_sprintfa(str,
@ -364,7 +364,7 @@ dcerpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
dcerpc_uuid_program->Data4[4], dcerpc_uuid_program->Data4[5], dcerpc_uuid_program->Data4[4], dcerpc_uuid_program->Data4[5],
dcerpc_uuid_program->Data4[6], dcerpc_uuid_program->Data4[7], dcerpc_uuid_program->Data4[6], dcerpc_uuid_program->Data4[7],
dcerpc_version, 0); dcerpc_version, 0);
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry)); filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){ if(filter[0]!=0){
g_string_sprintfa(str, ",%s", filter); g_string_sprintfa(str, ",%s", filter);
} }

View File

@ -214,10 +214,10 @@ static void
fcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_) fcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{ {
GString *str; GString *str;
char *filter; const char *filter;
str = g_string_new("fc,srt"); str = g_string_new("fc,srt");
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry)); filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){ if(filter[0]!=0){
g_string_sprintfa(str,",%s", filter); g_string_sprintfa(str,",%s", filter);
} }

View File

@ -161,7 +161,7 @@ preview_set_filename(GtkWidget *prev, const gchar *cf_name)
} }
label = OBJECT_GET_DATA(prev, PREVIEW_FILENAME_KEY); label = OBJECT_GET_DATA(prev, PREVIEW_FILENAME_KEY);
gtk_label_set_text(GTK_LABEL(label), get_basename((char *)cf_name)); gtk_label_set_text(GTK_LABEL(label), get_basename(cf_name));
if (test_for_directory(cf_name) == EISDIR) { if (test_for_directory(cf_name) == EISDIR) {
label = OBJECT_GET_DATA(prev, PREVIEW_FORMAT_KEY); label = OBJECT_GET_DATA(prev, PREVIEW_FORMAT_KEY);
@ -645,10 +645,11 @@ file_open_cmd_cb(GtkWidget *widget, gpointer data _U_) {
/* user pressed "open" button */ /* user pressed "open" button */
static void static void
file_open_ok_cb(GtkWidget *w, gpointer fs) { file_open_ok_cb(GtkWidget *w, gpointer fs) {
gchar *cf_name, *rfilter, *s; gchar *cf_name, *s;
GtkWidget *filter_te, *m_resolv_cb, *n_resolv_cb, *t_resolv_cb; const gchar *rfilter;
dfilter_t *rfcode = NULL; GtkWidget *filter_te, *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
int err; dfilter_t *rfcode = NULL;
int err;
#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs))); cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@ -656,7 +657,7 @@ file_open_ok_cb(GtkWidget *w, gpointer fs) {
cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs))); cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
#endif #endif
filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY); filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY);
rfilter = (gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te)); rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
if (!dfilter_compile(rfilter, &rfcode)) { if (!dfilter_compile(rfilter, &rfcode)) {
bad_dfilter_alert_box(rfilter); bad_dfilter_alert_box(rfilter);
g_free(cf_name); g_free(cf_name);
@ -992,14 +993,15 @@ file_merge_cmd_cb(GtkWidget *widget, gpointer data _U_) {
static void static void
file_merge_ok_cb(GtkWidget *w, gpointer fs) { file_merge_ok_cb(GtkWidget *w, gpointer fs) {
gchar *cf_name, *rfilter, *s; gchar *cf_name, *s;
GtkWidget *filter_te, *rb; const gchar *rfilter;
dfilter_t *rfcode = NULL; GtkWidget *filter_te, *rb;
int err; dfilter_t *rfcode = NULL;
gboolean merge_ok; int err;
char *in_filenames[2]; gboolean merge_ok;
int out_fd; char *in_filenames[2];
char tmpname[128+1]; int out_fd;
char tmpname[128+1];
#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs))); cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@ -1007,7 +1009,7 @@ file_merge_ok_cb(GtkWidget *w, gpointer fs) {
cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs))); cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
#endif #endif
filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY); filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY);
rfilter = (gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te)); rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
if (!dfilter_compile(rfilter, &rfcode)) { if (!dfilter_compile(rfilter, &rfcode)) {
bad_dfilter_alert_box(rfilter); bad_dfilter_alert_box(rfilter);
g_free(cf_name); g_free(cf_name);

View File

@ -979,7 +979,7 @@ gtk_iostat_draw(void *g)
pruned pruned
*/ */
static GString * static GString *
enable_graph(io_stat_graph_t *gio, char *filter, char *field) enable_graph(io_stat_graph_t *gio, const char *filter, const char *field)
{ {
char real_filter[260]; char real_filter[260];
@ -1505,12 +1505,12 @@ create_ctrl_area(io_stat_t *io, GtkWidget *box)
static gint static gint
filter_callback(GtkWidget *widget _U_, io_stat_graph_t *gio) filter_callback(GtkWidget *widget _U_, io_stat_graph_t *gio)
{ {
char *filter; const char *filter;
char *field; const char *field;
header_field_info *hfi; header_field_info *hfi;
dfilter_t *dfilter; dfilter_t *dfilter;
field=(char *)gtk_entry_get_text(GTK_ENTRY(gio->calc_field)); field=gtk_entry_get_text(GTK_ENTRY(gio->calc_field));
/* this graph is not active, just update display and redraw */ /* this graph is not active, just update display and redraw */
if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gio->display_button))){ if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gio->display_button))){
@ -1612,7 +1612,7 @@ filter_callback(GtkWidget *widget _U_, io_stat_graph_t *gio)
} }
/* first check if the filter string is valid. */ /* first check if the filter string is valid. */
filter=(char *)gtk_entry_get_text(GTK_ENTRY(gio->filter_field)); filter=gtk_entry_get_text(GTK_ENTRY(gio->filter_field));
if(!dfilter_compile(filter, &dfilter)) { if(!dfilter_compile(filter, &dfilter)) {
bad_dfilter_alert_box(filter); bad_dfilter_alert_box(filter);
disable_graph(gio); disable_graph(gio);

View File

@ -249,10 +249,10 @@ static void
ldapstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_) ldapstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{ {
GString *str; GString *str;
char *filter; const char *filter;
str = g_string_new("ldap,srt"); str = g_string_new("ldap,srt");
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry)); filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){ if(filter[0]!=0){
g_string_sprintfa(str,",%s", filter); g_string_sprintfa(str,",%s", filter);
} }

View File

@ -1525,7 +1525,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
#ifdef HAVE_LIBPCAP #ifdef HAVE_LIBPCAP
char *command_name; const char *command_name;
#endif #endif
char *s; char *s;
int i; int i;

View File

@ -316,11 +316,11 @@ static void
rpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_) rpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{ {
GString *str; GString *str;
char *filter; const char *filter;
str = g_string_new("rpc,srt"); str = g_string_new("rpc,srt");
g_string_sprintfa(str, ",%d,%d", rpc_program, rpc_version); g_string_sprintfa(str, ",%d,%d", rpc_program, rpc_version);
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry)); filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){ if(filter[0]!=0){
g_string_sprintfa(str, ",%s", filter); g_string_sprintfa(str, ",%s", filter);
} }

View File

@ -252,10 +252,10 @@ static void
smbstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_) smbstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{ {
GString *str; GString *str;
char *filter; const char *filter;
str = g_string_new("smb,srt"); str = g_string_new("smb,srt");
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry)); filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){ if(filter[0]!=0){
g_string_sprintfa(str,",%s", filter); g_string_sprintfa(str,",%s", filter);
} }

View File

@ -85,16 +85,16 @@ dlg_destroy_cb(GtkWidget *item _U_, gpointer dialog_data)
static void static void
tap_dfilter_dlg_start_button_clicked(GtkWidget *item _U_, gpointer dialog_data) tap_dfilter_dlg_start_button_clicked(GtkWidget *item _U_, gpointer dialog_data)
{ {
char *filter; const char *filter;
char str[256]; char str[256];
tap_dfilter_dlg_list_item *dlg_data = (tap_dfilter_dlg_list_item *) dialog_data; tap_dfilter_dlg_list_item *dlg_data = (tap_dfilter_dlg_list_item *) dialog_data;
filter=(char *)gtk_entry_get_text(GTK_ENTRY(dlg_data->filter_entry)); filter=gtk_entry_get_text(GTK_ENTRY(dlg_data->filter_entry));
if(filter[0]==0){ if(filter[0]==0){
g_snprintf(str, sizeof(str), "%s", dlg_data->cont.init_string); g_snprintf(str, sizeof(str), "%s", dlg_data->cont.init_string);
} else { } else {
g_snprintf(str, sizeof(str), "%s,%s", dlg_data->cont.init_string, filter); g_snprintf(str, sizeof(str), "%s,%s", dlg_data->cont.init_string, filter);
} }
(dlg_data->cont.tap_init_cb)(str); (dlg_data->cont.tap_init_cb)(str);
} }